Change icon for Tkinter message

Is there a way to change the tkinter message box icon? 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()

      

Is it possible to change the icon from the default tkinter pen to a custom ico?

+4


source to share


2 answers


Yes, there is such an option. Assuming your root Tkinter instance is named root

, your import statement from tkinter import *

and your image file is named 'ico.gif'

:

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

      



Call this method after creating the object root

and before tagging messagebox

. The icon will apply to the root object as well as messagebox

.

+3


source


I have a music_app.py

file and a melody.ico

file

With Tkinter, you can use:

from tkinter import *
from tkinter import messagebox

root = Tk()
root.withdraw()
root.iconbitmap(r"melody.ico")
messagebox.showinfo('Infor', 'Enjoin music !!!')
root.mainloop()

      



And the result:

enter image description here

Hope this helps!

0


source







All Articles