Skip to content

Commit 7ce09fc

Browse files
[3.12] gh-128014: Fix passing default='' to the tkinter method wm_iconbitmap() (GH-128015) (GH-128420)
(cherry picked from commit 58e9f95) Co-authored-by: Zhikang Yan <[email protected]>
1 parent 52c08ed commit 7ce09fc

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

Lib/test/test_tkinter/test_misc.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import tkinter
44
import enum
55
from test import support
6-
from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest
6+
from test.test_tkinter.support import (AbstractTkTest, AbstractDefaultRootTest,
7+
requires_tk, get_tk_patchlevel)
78

89
support.requires('gui')
910

@@ -392,6 +393,34 @@ def test_embedded_null(self):
392393
self.assertEqual(widget.selection_get(), '\u20ac\0abc\x00def')
393394

394395

396+
class WmTest(AbstractTkTest, unittest.TestCase):
397+
398+
def test_wm_iconbitmap(self):
399+
t = tkinter.Toplevel(self.root)
400+
self.assertEqual(t.wm_iconbitmap(), '')
401+
t.wm_iconbitmap('hourglass')
402+
bug = False
403+
if t._windowingsystem == 'aqua':
404+
# Tk bug 13ac26b35dc55f7c37f70b39d59d7ef3e63017c8.
405+
patchlevel = get_tk_patchlevel(t)
406+
if patchlevel < (8, 6, 17) or (9, 0) <= patchlevel < (9, 0, 2):
407+
bug = True
408+
if not bug:
409+
self.assertEqual(t.wm_iconbitmap(), 'hourglass')
410+
self.assertEqual(self.root.wm_iconbitmap(), '')
411+
t.wm_iconbitmap('')
412+
self.assertEqual(t.wm_iconbitmap(), '')
413+
414+
if t._windowingsystem == 'win32':
415+
t.wm_iconbitmap(default='hourglass')
416+
self.assertEqual(t.wm_iconbitmap(), 'hourglass')
417+
self.assertEqual(self.root.wm_iconbitmap(), '')
418+
t.wm_iconbitmap(default='')
419+
self.assertEqual(t.wm_iconbitmap(), '')
420+
421+
t.destroy()
422+
423+
395424
class EventTest(AbstractTkTest, unittest.TestCase):
396425

397426
def test_focus(self):

Lib/tkinter/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ def wm_iconbitmap(self, bitmap=None, default=None):
21502150
explicitly. DEFAULT can be the relative path to a .ico file
21512151
(example: root.iconbitmap(default='myicon.ico') ). See Tk
21522152
documentation for more information."""
2153-
if default:
2153+
if default is not None:
21542154
return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
21552155
else:
21562156
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix resetting the default window icon by passing ``default=''`` to the
2+
:mod:`tkinter` method :meth:`!wm_iconbitmap`.

0 commit comments

Comments
 (0)