帮助更改Tk窗口图标

4 投票
1 回答
2584 浏览
提问于 2025-04-16 13:57
root = Tk()


w=350
h=200

# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
    # calculate position x, y

x = (ws/2) - (w/2)
y = (hs/2) - (h/2)

root.geometry('%dx%d+%d+%d' % (w, h, x, y))

root.iconbitmap(default='images/account.gif')

Label(root, text='Window with transparent icon.').pack()

root.title("Create a window")

我遇到了一个错误

File "Project.py", line 46, in <module>
root.iconbitmap(default='images/account.gif')
File "/usr/lib/python2.6/lib-tk/Tkinter.py", line 1523, in wm_iconbitmap
return self.tk.call('wm', 'iconbitmap', self._w, '-default', default)
_tkinter.TclError: wrong # args: should be "wm iconbitmap window ?bitmap?"

我还想更改窗口的托盘图标

1 个回答

2

你需要提供一个 bitmap 参数,不能仅仅给它一个 default。另外,你不能用 .gif 格式的图片。它需要是 .xbm 格式的,或者在 Windows 上我记得是 .ico 格式的。

撰写回答