Skip to content

Commit 58e9f95

Browse files
pythongh-128014: Fix passing default='' to the tkinter method wm_iconbitmap() (pythonGH-128015)
Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent c9d2bc6 commit 58e9f95

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Lib/test/test_tkinter/test_misc.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
from tkinter import TclError
55
import enum
66
from test import support
7-
from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest, requires_tk
7+
from test.test_tkinter.support import (AbstractTkTest, AbstractDefaultRootTest,
8+
requires_tk, get_tk_patchlevel)
89

910
support.requires('gui')
1011

@@ -554,6 +555,31 @@ def test_wm_attribute(self):
554555
self.assertEqual(w.wm_attributes('alpha'),
555556
1.0 if self.wantobjects else '1.0')
556557

558+
def test_wm_iconbitmap(self):
559+
t = tkinter.Toplevel(self.root)
560+
self.assertEqual(t.wm_iconbitmap(), '')
561+
t.wm_iconbitmap('hourglass')
562+
bug = False
563+
if t._windowingsystem == 'aqua':
564+
# Tk bug 13ac26b35dc55f7c37f70b39d59d7ef3e63017c8.
565+
patchlevel = get_tk_patchlevel(t)
566+
if patchlevel < (8, 6, 17) or (9, 0) <= patchlevel < (9, 0, 2):
567+
bug = True
568+
if not bug:
569+
self.assertEqual(t.wm_iconbitmap(), 'hourglass')
570+
self.assertEqual(self.root.wm_iconbitmap(), '')
571+
t.wm_iconbitmap('')
572+
self.assertEqual(t.wm_iconbitmap(), '')
573+
574+
if t._windowingsystem == 'win32':
575+
t.wm_iconbitmap(default='hourglass')
576+
self.assertEqual(t.wm_iconbitmap(), 'hourglass')
577+
self.assertEqual(self.root.wm_iconbitmap(), '')
578+
t.wm_iconbitmap(default='')
579+
self.assertEqual(t.wm_iconbitmap(), '')
580+
581+
t.destroy()
582+
557583

558584
class EventTest(AbstractTkTest, unittest.TestCase):
559585

Lib/tkinter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,7 @@ def wm_iconbitmap(self, bitmap=None, default=None):
22652265
explicitly. DEFAULT can be the relative path to a .ico file
22662266
(example: root.iconbitmap(default='myicon.ico') ). See Tk
22672267
documentation for more information."""
2268-
if default:
2268+
if default is not None:
22692269
return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
22702270
else:
22712271
return self.tk.call('wm', 'iconbitmap', self._w, bitmap)
Lines changed: 2 additions & 0 deletions
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)