更改Tkinter消息框的图标


问题内容

有没有办法更改tkinter消息框的图标?这是我的代码:

from tkinter import *
import tkinter.messagebox as messagebox

root = Tk()
messagebox.showinfo(title="Example",message='This is an example')
root.mainloop()

是否可以将图标从默认的Tkinter Feather更改为自定义ico?


问题答案:

是的,有这样的选择。假设您的根Tkinter实例被调用root,您的import语句为from tkinter import *,并且您的图像文件名为'ico.gif'

root.tk.call('wm', 'iconphoto', root._w, PhotoImage(file='ico.gif'))

创建root对象之后并弹出之前,请调用此方法messagebox。该图标将应用于根对象和messagebox