Skip to content

Commit 3bb3fb3

Browse files
bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (#25187)
1 parent 8cc3cfa commit 3bb3fb3

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

Lib/idlelib/config_key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from tkinter import Toplevel, Listbox, StringVar, TclError
55
from tkinter.ttk import Frame, Button, Checkbutton, Entry, Label, Scrollbar
66
from tkinter import messagebox
7+
from tkinter.simpledialog import _setup_dialog
78
import string
89
import sys
910

@@ -63,6 +64,7 @@ def __init__(self, parent, title, action, current_key_sequences,
6364
self.resizable(height=False, width=False)
6465
self.title(title)
6566
self.transient(parent)
67+
_setup_dialog(self)
6668
self.grab_set()
6769
self.protocol("WM_DELETE_WINDOW", self.cancel)
6870
self.parent = parent

Lib/idlelib/query.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from tkinter.ttk import Frame, Button, Entry, Label, Checkbutton
2929
from tkinter import filedialog
3030
from tkinter.font import Font
31+
from tkinter.simpledialog import _setup_dialog
3132

3233
class Query(Toplevel):
3334
"""Base class for getting verified answer from a user.
@@ -60,13 +61,8 @@ def __init__(self, parent, title, message, *, text0='', used_names={},
6061
if not _utest: # Otherwise fail when directly run unittest.
6162
self.grab_set()
6263

63-
windowingsystem = self.tk.call('tk', 'windowingsystem')
64-
if windowingsystem == 'aqua':
65-
try:
66-
self.tk.call('::tk::unsupported::MacWindowStyle', 'style',
67-
self._w, 'moveableModal', '')
68-
except:
69-
pass
64+
_setup_dialog(self)
65+
if self._windowingsystem == 'aqua':
7066
self.bind("<Command-.>", self.cancel)
7167
self.bind('<Key-Escape>', self.cancel)
7268
self.protocol("WM_DELETE_WINDOW", self.cancel)

Lib/idlelib/searchbase.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from tkinter import Toplevel
44
from tkinter.ttk import Frame, Entry, Label, Button, Checkbutton, Radiobutton
5+
from tkinter.simpledialog import _setup_dialog
56

67

78
class SearchDialogBase:
@@ -83,6 +84,7 @@ def create_widgets(self):
8384
top.protocol("WM_DELETE_WINDOW", self.close)
8485
top.wm_title(self.title)
8586
top.wm_iconname(self.icon)
87+
_setup_dialog(top)
8688
self.top = top
8789
self.frame = Frame(top, padding="5px")
8890
self.frame.grid(sticky="nwes")

Lib/tkinter/filedialog.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
from tkinter.dialog import Dialog
2626
from tkinter import commondialog
27+
from tkinter.simpledialog import _setup_dialog
2728

2829

2930
dialogstates = {}
@@ -62,6 +63,7 @@ def __init__(self, master, title=None):
6263
self.top = Toplevel(master)
6364
self.top.title(title)
6465
self.top.iconname(title)
66+
_setup_dialog(self.top)
6567

6668
self.botframe = Frame(self.top)
6769
self.botframe.pack(side=BOTTOM, fill=X)

Lib/tkinter/simpledialog.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def __init__(self, master,
4040
if title:
4141
self.root.title(title)
4242
self.root.iconname(title)
43+
44+
_setup_dialog(self.root)
45+
4346
self.message = Message(self.root, text=text, aspect=400)
4447
self.message.pack(expand=1, fill=BOTH)
4548
self.frame = Frame(self.root)
@@ -115,6 +118,8 @@ def __init__(self, parent, title = None):
115118
if title:
116119
self.title(title)
117120

121+
_setup_dialog(self)
122+
118123
self.parent = parent
119124

120125
self.result = None
@@ -252,6 +257,13 @@ def _place_window(w, parent=None):
252257
w.wm_deiconify() # Become visible at the desired location
253258

254259

260+
def _setup_dialog(w):
261+
if w._windowingsystem == "aqua":
262+
w.tk.call("::tk::unsupported::MacWindowStyle", "style",
263+
w, "moveableModal", "")
264+
elif w._windowingsystem == "x11":
265+
w.wm_attributes("-type", "dialog")
266+
255267
# --------------------------------------------------------------------
256268
# convenience dialogues
257269

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
IDLE dialog windows are now recognized as dialogs by window managers on
2+
macOS and X Window.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`tkinter` dialog windows are now recognized as dialogs by window
2+
managers on macOS and X Window.

0 commit comments

Comments
 (0)