https://github.com/python/cpython/commit/e5ef47e94f7c9d970ad98e2c33870ccc3b04dc5c
commit: e5ef47e94f7c9d970ad98e2c33870ccc3b04dc5c
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-10-17T16:36:03+03:00
summary:

gh-159517: Do not use ::tk::unsupported::MacWindowStyle in IDLE on Tk 9.1 
(GH-159527)

Tk 9.1 no longer provides this command.  Use "wm attributes -stylemask
docmodal" instead, as Tk itself does for its balloon window.  The calls
were silently ignored, so the completion list and the call tip could
grab the focus on macOS.

files:
A Misc/NEWS.d/next/IDLE/2026-10-16-15-12-36.gh-issue-159517.uzRtAd.rst
M Lib/idlelib/autocomplete_w.py
M Lib/idlelib/tooltip.py

diff --git a/Lib/idlelib/autocomplete_w.py b/Lib/idlelib/autocomplete_w.py
index 24320b5a3bffab3..b28edffa2b0c710 100644
--- a/Lib/idlelib/autocomplete_w.py
+++ b/Lib/idlelib/autocomplete_w.py
@@ -185,12 +185,14 @@ def show_window(self, comp_lists, index, complete, mode, 
userWantsWin):
         self.autocompletewindow = acw = Toplevel(self.widget)
         acw.withdraw()
         acw.wm_overrideredirect(1)
-        try:
+        if acw._windowingsystem == 'aqua':
             # Prevent grabbing focus on macOS.
-            acw.tk.call("::tk::unsupported::MacWindowStyle", "style", acw._w,
-                        "help", "noActivates")
-        except TclError:
-            pass
+            if acw.info_patchlevel() >= (9, 1):
+                acw.update_idletasks()
+                acw.wm_attributes(stylemask='docmodal')
+            else:
+                acw.tk.call('::tk::unsupported::MacWindowStyle', 'style',
+                            acw._w, 'help', 'noActivates')
         self.scrollbar = scrollbar = Scrollbar(acw, orient=VERTICAL)
         self.listbox = listbox = Listbox(acw, yscrollcommand=scrollbar.set,
                                          exportselection=False)
diff --git a/Lib/idlelib/tooltip.py b/Lib/idlelib/tooltip.py
index df5b1fe1dcfb080..f88ac604b1b5683 100644
--- a/Lib/idlelib/tooltip.py
+++ b/Lib/idlelib/tooltip.py
@@ -30,14 +30,15 @@ def showtip(self):
         self.tipwindow = tw = Toplevel(self.anchor_widget)
         # show no border on the top level window
         tw.wm_overrideredirect(1)
-        try:
-            # This command is only needed and available on Tk >= 8.4.0 for OSX.
-            # Without it, call tips intrude on the typing process by grabbing
-            # the focus.
-            tw.tk.call("::tk::unsupported::MacWindowStyle", "style", tw._w,
-                       "help", "noActivates")
-        except TclError:
-            pass
+        if tw._windowingsystem == 'aqua':
+            # Without this, call tips intrude on the typing process by
+            # grabbing the focus.
+            if tw.info_patchlevel() >= (9, 1):
+                tw.update_idletasks()
+                tw.wm_attributes(stylemask='docmodal')
+            else:
+                tw.tk.call('::tk::unsupported::MacWindowStyle', 'style',
+                           tw._w, 'help', 'noActivates')
 
         self.position_window()
         self.showcontents()
diff --git 
a/Misc/NEWS.d/next/IDLE/2026-10-16-15-12-36.gh-issue-159517.uzRtAd.rst 
b/Misc/NEWS.d/next/IDLE/2026-10-16-15-12-36.gh-issue-159517.uzRtAd.rst
new file mode 100644
index 000000000000000..f5e506c3e1f96e5
--- /dev/null
+++ b/Misc/NEWS.d/next/IDLE/2026-10-16-15-12-36.gh-issue-159517.uzRtAd.rst
@@ -0,0 +1,2 @@
+Fix the completion list and the call tip grabbing the focus on macOS with
+Tcl/Tk 9.1.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to