Skip to content

Commit

Permalink
[3.11] gh-113877: Fix Tkinter method winfo_pathname() on 64-bit Windo…
Browse files Browse the repository at this point in the history
…ws (GH-113900) (GH-113902)

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 1b7e002)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
  • Loading branch information
miss-islington and serhiy-storchaka committed Jan 10, 2024
1 parent 86b0043 commit b4a6bbd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/tkinter/__init__.py
Expand Up @@ -1181,6 +1181,8 @@ def winfo_parent(self):

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)
Expand Down
12 changes: 12 additions & 0 deletions Lib/tkinter/test/test_tkinter/test_misc.py
Expand Up @@ -227,6 +227,18 @@ def assertApprox(col1, col2):
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
Expand Down
@@ -0,0 +1 @@
Fix :mod:`tkinter` method ``winfo_pathname()`` on 64-bit Windows.

0 comments on commit b4a6bbd

Please sign in to comment.