]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-113877: Fix Tkinter method winfo_pathname() on 64-bit Windows (GH-113900)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 10 Jan 2024 10:36:03 +0000 (12:36 +0200)
committerGitHub <noreply@github.com>
Wed, 10 Jan 2024 10:36:03 +0000 (12:36 +0200)
winfo_id() converts the result of "winfo id" command to integer, but
"winfo pathname" command requires an argument to be a hexadecimal number
on Win64.

Lib/test/test_tkinter/test_misc.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2024-01-10-12-03-38.gh-issue-113877.RxKlrQ.rst [new file with mode: 0644]

index 6639eaaa59936a9633cd296ee67e8c6cf397afe7..dc8a810235fc9bd5566e948317afedad5cc4d0a7 100644 (file)
@@ -281,6 +281,18 @@ class MiscTest(AbstractTkTest, unittest.TestCase):
         with self.assertRaises(tkinter.TclError):
             rgb((111, 78, 55))
 
+    def test_winfo_pathname(self):
+        t = tkinter.Toplevel(self.root)
+        w = tkinter.Button(t)
+        wid = w.winfo_id()
+        self.assertIsInstance(wid, int)
+        self.assertEqual(self.root.winfo_pathname(hex(wid)), str(w))
+        self.assertEqual(self.root.winfo_pathname(hex(wid), displayof=None), str(w))
+        self.assertEqual(self.root.winfo_pathname(hex(wid), displayof=t), str(w))
+        self.assertEqual(self.root.winfo_pathname(wid), str(w))
+        self.assertEqual(self.root.winfo_pathname(wid, displayof=None), str(w))
+        self.assertEqual(self.root.winfo_pathname(wid, displayof=t), str(w))
+
     def test_event_repr_defaults(self):
         e = tkinter.Event()
         e.serial = 12345
index 124882420c255c3754ef4b59d0b69977701db8ed..2590acdc87e695a433de70076abeadea04a0c0b4 100644 (file)
@@ -1260,6 +1260,8 @@ class Misc:
 
     def winfo_pathname(self, id, displayof=0):
         """Return the pathname of the widget given by ID."""
+        if isinstance(id, int):
+            id = hex(id)
         args = ('winfo', 'pathname') \
                + self._displayof(displayof) + (id,)
         return self.tk.call(args)
diff --git a/Misc/NEWS.d/next/Library/2024-01-10-12-03-38.gh-issue-113877.RxKlrQ.rst b/Misc/NEWS.d/next/Library/2024-01-10-12-03-38.gh-issue-113877.RxKlrQ.rst
new file mode 100644 (file)
index 0000000..173e185
--- /dev/null
@@ -0,0 +1 @@
+Fix :mod:`tkinter` method ``winfo_pathname()`` on 64-bit Windows.