`tkinter.iconbitmap` method returns empty string

I have an app:

class App(tk.Tk):
    def __init__(self):
        # Set app title
        self.app_title = 'Visual Python'
        # Set app icon

And a test:

class TestApp(unittest.TestCase):
    def setUp(self):
        self.app = App()

    def test_app_title(self):
        self.assertEqual(self.app.title(), 'Visual Python')

    def test_app_icon(self):
        self.assertEqual(self.app.iconbitmap(), 'icon.ico')

When I ran the test with py -3 -m unittest, I get this output:

FAIL: test_app_icon (test.test_app.TestApp)
Traceback (most recent call last):
  File "C:\Users\ismailarilik\visual-python\test\test_app.py", line 12, in 
    self.assertEqual(self.app.iconbitmap(), 'icon.ico')
AssertionError: '' != 'icon.ico'
+ icon.ico

Ran 2 tests in 0.279s

FAILED (failures=1)

Why does iconbitmap method here return an empty string instead of the given 'icon.ico' string?

1 answer

  • answered 2018-07-18 08:14 Billal BEGUERADJ


    If an empty string is specified for bitmap, then any current icon bitmap is cancelled for window. If bitmap is specified then the command returns an empty string. Otherwise it returns the name of the current icon bitmap associated with window, or an empty string if window has no icon bitmap.

    I think your situation falls into the last case highlighted in bold text. I mean you have to be sure the icon is set correctly, depending on your platform.