You want to put an icon into your app made with Python and tkinter? Read this post and you’ll get to the point.
I got this icon that is a png file. I want to add it to a window of tkinter, having the image in the same directory of the code.
This to me does not work
import tkinter as tk root = tk.Tk() root.iconbitmap("calculator.png") root.mainloop()
I get this result and no error message
So, I tried this
import tkinter as tk root = tk.Tk() root.tk.call('wm', 'iconphoto', root._w, tk.PhotoImage(file='calculator.png')) root.mainloop()
and it worked, cool
import tkinter as tk root = tk.Tk() root.tk.call('wm', 'iconphoto', root._w, tk.PhotoImage(file='calculator.png')) root.mainloop()
This was the result, as you can see I got the image in the top left of the window, as I wanted.
See ya in the next post
Subscribe to the newsletter for updates
Tkinter templates
My youtube channel
Twitter: @pythonprogrammi - python_pygame