python - `tkinter.iconbitmap` 方法返回空字符串

标签 python unit-testing tkinter

我有一个应用程序:

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

还有一个测试:

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')

当我使用 py -3 -m unittest 运行测试时,我得到以下输出:

F.
======================================================================
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 
test_app_icon
    self.assertEqual(self.app.iconbitmap(), 'icon.ico')
AssertionError: '' != 'icon.ico'
+ icon.ico

----------------------------------------------------------------------
Ran 2 tests in 0.279s

FAILED (failures=1)

为什么此处的 iconbitmap 方法返回空字符串而不是给定的 'icon.ico' 字符串?

最佳答案

Source :

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.

我认为您的情况属于最后一种以粗体文本突出显示的情况。我的意思是你必须确保图标已设置 correctly ,取决于您的平台。

关于python - `tkinter.iconbitmap` 方法返回空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51395141/

相关文章:

unit-testing - 为什么 PHPunit 使用 Silex 请求 KERNEL_DIR?

单元测试期间的 Python 日志捕获

python - 为什么 from tkinter import * 不导入 Tkinter 的消息框?

Python Mysql - 查询语法错误

python - 如何在 python 中使用十六进制值而不是 RGB 值。 Python 2.7

python - 将 DataFrame 插入/附加到 MultiIndex DataFrame

Python命令行程序: generate man page from existing documentation and include in the distribution

python - Python 上的 Unicode 错误

angular - 如何在 Angular2 中测试包含(ng-content)?

python - 如何使用Python中的Tkinter,使用几个选定颜色的迭代来更改Python中的圆圈颜色,这些颜色随着每次按下按钮而变化?