Skip to content

Commit

Permalink
Modal dialogs get focus on show. Escape closes them
Browse files Browse the repository at this point in the history
  • Loading branch information
Aesonus committed Dec 15, 2020
1 parent 9d47d10 commit d75186b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tklife/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, **kwargs):
self.withdraw()
self.cancelled = False
self.protocol("WM_DELETE_WINDOW", self._on_cancel)
self.bind('<Escape>', self._on_cancel)

def _on_cancel(self):
"""
Expand All @@ -61,6 +62,7 @@ def show(dialog_class, master, **kwargs):
new = dialog_class(master=master, **kwargs)
new.deiconify()
new.grab_set()
new.focus_set()
new.wait_window()
if (new.cancelled):
return None
Expand Down

0 comments on commit d75186b

Please sign in to comment.