Skip to content

Commit 7530c61

Browse files
[3.12] gh-113877: Fix Tkinter method winfo_pathname() on 64-bit Windows (GH-113900) (GH-113901)
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 <[email protected]>
1 parent 159e3db commit 7530c61

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
@@ -227,6 +227,18 @@ def assertApprox(col1, col2):
227227
with self.assertRaises(tkinter.TclError):
228228
rgb((111, 78, 55))
229229

230+
def test_winfo_pathname(self):
231+
t = tkinter.Toplevel(self.root)
232+
w = tkinter.Button(t)
233+
wid = w.winfo_id()
234+
self.assertIsInstance(wid, int)
235+
self.assertEqual(self.root.winfo_pathname(hex(wid)), str(w))
236+
self.assertEqual(self.root.winfo_pathname(hex(wid), displayof=None), str(w))
237+
self.assertEqual(self.root.winfo_pathname(hex(wid), displayof=t), str(w))
238+
self.assertEqual(self.root.winfo_pathname(wid), str(w))
239+
self.assertEqual(self.root.winfo_pathname(wid, displayof=None), str(w))
240+
self.assertEqual(self.root.winfo_pathname(wid, displayof=t), str(w))
241+
230242
def test_event_repr_defaults(self):
231243
e = tkinter.Event()
232244
e.serial = 12345

Lib/tkinter/__init__.py

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

11821182
def winfo_pathname(self, id, displayof=0):
11831183
"""Return the pathname of the widget given by ID."""
1184+
if isinstance(id, int):
1185+
id = hex(id)
11841186
args = ('winfo', 'pathname') \
11851187
+ self._displayof(displayof) + (id,)
11861188
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)