簡體   English   中英

Tkinter 去掉消息框里的 python 圖標 tkinter

[英]Tkinter get rid of the python icon in messagebox tkinter

運行此代碼時如何擺脫 Python (或matplotlib )圖標? 即使我添加icon='info' ,我仍然得到帶有 python 徽標的火箭。 請檢查參考中的照片。

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用於更改消息框內的圖標。 在這里回答得很好。


參考這個問題及其評論,一種解決方案是使用tk.Toplevel()創建您自己的自定義消息框

這是您將如何編碼的示例。 (您可以進一步提高多個消息框的效率):

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 圖標文件更改默認圖標的解決方案,對於整個 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM