更改 Tkinter 消息框的图标 [英] Change Icon For Tkinter Messagebox

查看:88
本文介绍了更改 Tkinter 消息框的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a way to change the icon of a tkinter message box? Here is my code:

from tkinter import *
import tkinter.messagebox as messagebox

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

是否可以将图标从默认的 tkinter 羽毛更改为自定义图标?

Is there an option to change the icon from the default tkinter feather to a custom ico?

推荐答案

是的,有这样的选项.假设您的根 Tkinter 实例名为 root,您的导入语句为 from tkinter import *,并且您的图像文件名为 'ico.gif':

Yes, there is such an option. Assuming your root Tkinter instance is called root, your import statement is from tkinter import *, and your image file is named 'ico.gif':

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

在创建root 对象之后和弹出messagebox 之前调用此方法.该图标将应用于根对象以及 messagebox.

Call this method after creating the root object and before popping the messagebox. The icon will apply to the root object as well as to the messagebox.

这篇关于更改 Tkinter 消息框的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆