【发布时间】:2021-06-29 16:54:18
【问题描述】:
我想为顶级窗口和子窗口替换默认的 python tkinter 图标。我已经尝试了几件导致错误的事情。替换父窗口和子窗口图标的最佳方法是什么?请参阅下面的尝试 - 我正在使用 python 3.9.1
import tkinter as tk
from PIL import Image, ImageTk
m = tk.Tk()
m.title('Main Window')
m.geometry('300x100')
blankImageObject = tk.PhotoImage(file='icons/blankIcon.png')
m.tk.call('wm', 'iconphoto', m._w, blankImageObject)
c = tk.Tk('m')
c.title('Child Window')
c.geometry('300x100')
#try to re-use the same image object created for the main window
#c.tk.call('wm', 'iconphoto', c._w, blankImageObject)
#try creating a new PhotoImage object
#c.tk.call('wm', 'iconphoto', c._w, tk.PhotoImage(file='icons/blankIcon.png'))
#try using main window instead of the child window in the Tcl call
#c.tk.call('wm', 'iconphoto', m._w, tk.PhotoImage(file='icons/blankIcon.png'))
#try using main window in the Tcl call and the blankImageObject from the main window
#c.tk.call('wm', 'iconphoto', m._w, blankImageObject)
m.mainloop()
【问题讨论】:
-
您想一次性替换所有窗口?