Skip to content

Commit 1b7e002

Browse files
gh-113877: Fix Tkinter method winfo_pathname() on 64-bit Windows (GH-113900)
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.
1 parent 5d384b0 commit 1b7e002

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Lib/test/test_tkinter/test_misc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,18 @@ def assertApprox(col1, col2):
281281
with self.assertRaises(tkinter.TclError):
282282
rgb((111, 78, 55))
283283

284+
def test_winfo_pathname(self):
285+
t = tkinter.Toplevel(self.root)
286+
w = tkinter.Button(t)
287+
wid = w.winfo_id()
288+
self.assertIsInstance(wid, int)
289+
self.assertEqual(self.root.winfo_pathname(hex(wid)), str(w))
290+
self.assertEqual(self.root.winfo_pathname(hex(wid), displayof=None), str(w))
291+
self.assertEqual(self.root.winfo_pathname(hex(wid), displayof=t), str(w))
292+
self.assertEqual(self.root.winfo_pathname(wid), str(w))
293+
self.assertEqual(self.root.winfo_pathname(wid, displayof=None), str(w))
294+
self.assertEqual(self.root.winfo_pathname(wid, displayof=t), str(w))
295+
284296
def test_event_repr_defaults(self):
285297
e = tkinter.Event()
286298
e.serial = 12345

Lib/tkinter/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,8 @@ def winfo_parent(self):
12601260

12611261
def winfo_pathname(self, id, displayof=0):
12621262
"""Return the pathname of the widget given by ID."""
1263+
if isinstance(id, int):
1264+
id = hex(id)
12631265
args = ('winfo', 'pathname') \
12641266
+ self._displayof(displayof) + (id,)
12651267
return self.tk.call(args)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix :mod:`tkinter` method ``winfo_pathname()`` on 64-bit Windows.

0 commit comments

Comments
 (0)