首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tkinter去掉messagebox tkinter中的python图标

Tkinter去掉messagebox tkinter中的python图标
EN

Stack Overflow用户
提问于 2022-05-13 16:31:23
回答 1查看 76关注 0票数 0

在运行这段代码时,我如何摆脱Python (或matplotlib)图标?即使我添加了icon='info',我仍然可以得到带有python徽标的火箭。请查阅参考照片。

代码语言:javascript
复制
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()

EN

回答 1

Stack Overflow用户

发布于 2022-05-14 02:48:36

icon=info用于更改消息框中的图标。这里回答得很好。

提及这一问题及其评论,一种解决方案可以是使用tk.Toplevel()创建您自己的自定义messagebox

下面是一个示例,说明您将如何对其进行编码。(您可以进一步提高对多个消息框的效率):

代码语言:javascript
复制
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()

但是,如果您正在寻找的解决方案,请使用.ico图标文件更改默认图标,对于包括MessageBox 请参阅这里在内的整个Tkinter窗口,只需使用iconbitmap

代码语言:javascript
复制
import tkinter as tk


win = tk.Tk()
win.title("example")
win.iconbitmap(".ico file location")

win.mainloop()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72232756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档