[英]Tkinter get rid of the python icon in messagebox tkinter
How can I get rid of the Python (or matplotlib
) icon when running this code?运行此代码时如何摆脱 Python (或
matplotlib
)图标? Even when I add icon='info'
, I still get the rocket with the python logo.即使我添加
icon='info'
,我仍然得到带有 python 徽标的火箭。 Please check the photo in reference.请检查参考中的照片。
from tkinter import * import tkinter as tk from tkinter import messagebox as tm
root=Tk() root.geometry("1200x1200") canvas1 = tk.Canvas(root, width = 300, height = 300) canvas1.pack() def ExitApplication():
text=text= ' Our team thank you for your visit ! '
MsgBox=tk.messagebox.askquestion('Exit the platform' , text, icon='info')
if MsgBox=='yes':
root.destroy()
else:
tk.messagebox.showinfo('Return', 'You will now return to the application screen ', icon='info')
exit_button = Button(root, text="Exit ", command=ExitApplication) canvas1.create_window(200, 200, window=exit_button)
root.mainloop()
icon=info
is used for changing the icon inside message box. icon=info
用于更改消息框内的图标。 Answered here nicely. 在这里回答得很好。
Referring to this question and its comments , one solution could be to create your own custom messagebox using tk.Toplevel()
:参考这个问题及其评论,一种解决方案是使用
tk.Toplevel()
创建您自己的自定义消息框:
Here is an example of how you would be coding it.这是您将如何编码的示例。 (You can further make it more efficient for multiple messageboxes):
(您可以进一步提高多个消息框的效率):
from tkinter import *
import tkinter as tk
#from tkinter import messagebox as tm
root=Tk()
root.geometry("1200x1200")
canvas1 = tk.Canvas(root, width = 300, height = 300)
canvas1.pack()
def ExitApplication():
text = ' Our team thank you for your visit ! '
MsgBox=Toplevel(root)
MsgBox.title("Exit the platform")
MsgBox.geometry(f"300x100+{root.winfo_x()}+{root.winfo_y()}")
icon = PhotoImage(file="Any image file")#provide here the image file location
MsgBox.iconphoto(True, icon)
l1=Label(MsgBox, image="::tk::icons::question")
l1.grid(row=0, column=0, pady=(7, 0), padx=(10, 30), sticky="e")
l2=Label(MsgBox,text=text)
l2.grid(row=0, column=1, columnspan=3, pady=(7, 10), sticky="w")
b1=Button(MsgBox,text="Yes",command=root.destroy,width = 10)
b1.grid(row=1, column=1, padx=(2, 35), sticky="e")
b2=Button(MsgBox,text="No",command=lambda:[MsgBox.destroy(), returnBack()],width = 10)
b2.grid(row=1, column=2, padx=(2, 35), sticky="e")
def returnBack():
pass
#Similarly, create a custom messagebox using Toplevel() for showing the following info:
#tk.messagebox.showinfo('Return', 'You will now return to the application screen ', icon='info')
exit_button = Button(root, text="Exit ", command=ExitApplication)
canvas1.create_window(200, 200, window=exit_button)
root.mainloop()
But if you are looking for a solution to change the default icon with an.ico icon file , for entire Tkinter windows including MessageBox refer here , just use iconbitmap
:但是,如果您正在寻找使用 .ico 图标文件更改默认图标的解决方案,对于整个 Tkinter windows 包括 MessageBox, 请参考此处,只需使用
iconbitmap
:
import tkinter as tk
win = tk.Tk()
win.title("example")
win.iconbitmap(".ico file location")
win.mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.