Skip to content

Commit 9a16539

Browse files
[3.9] bpo-43655: Tkinter and IDLE dialog windows are now recognized as dialogs by window managers on macOS and X Window (GH-25187). (GH-25588)
(cherry picked from commit 3bb3fb3)
1 parent 7248ce3 commit 9a16539

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
@@ -39,6 +39,9 @@ def __init__(self, master,
3939
if title:
4040
self.root.title(title)
4141
self.root.iconname(title)
42+
43+
_setup_dialog(self.root)
44+
4245
self.message = Message(self.root, text=text, aspect=400)
4346
self.message.pack(expand=1, fill=BOTH)
4447
self.frame = Frame(self.root)
@@ -142,6 +145,8 @@ def __init__(self, parent, title = None):
142145
if title:
143146
self.title(title)
144147

148+
_setup_dialog(self)
149+
145150
self.parent = parent
146151

147152
self.result = None
@@ -251,6 +256,13 @@ def apply(self):
251256
pass # override
252257

253258

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

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)