]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-113877: Fix Tkinter method winfo_pathname() on 64-bit Windows (GH-113900...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 10 Jan 2024 10:50:51 +0000 (11:50 +0100)
committerGitHub <noreply@github.com>
Wed, 10 Jan 2024 10:50:51 +0000 (10:50 +0000)
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.
(cherry picked from commit 1b7e0024a16c1820f61c04a8a100498568410afd)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/tkinter/__init__.py
Lib/tkinter/test/test_tkinter/test_misc.py
Misc/NEWS.d/next/Library/2024-01-10-12-03-38.gh-issue-113877.RxKlrQ.rst [new file with mode: 0644]

index 05558e97733cd9a33864ef391b3d61c470d63069..012737c0d7bae38a0a67c38b30f0ba994e256d3d 100644 (file)
@@ -1181,6 +1181,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)
index aa11e65ea948ce8472958570f9ae3f2130e59d46..11f5b32e4b8995344869a385a7791cba6ff0f2dd 100644 (file)
@@ -227,6 +227,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
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.