I don't know why the image not showing.
Is this a device problem or some update in the Tkinter library?
from tkinter import *
root = Tk()
btn = Button(master=root,image=PhotoImage(file='Sample1.png'))
btn.pack()
root.mainloop()
Sample Image:
I don't know why the image not showing.
Is this a device problem or some update in the Tkinter library?
from tkinter import *
root = Tk()
btn = Button(master=root,image=PhotoImage(file='Sample1.png'))
btn.pack()
root.mainloop()
Sample Image:
When a PhotoImage object is garbage-collected by Python (e.g. when you return from a function which stored an image in a local variable), the image is cleared even if it’s being displayed by a Tkinter widget.
Python garbage-collects any local objects at the end of the scope, even when being used by a Tkinter widget. To prevent this, you need to assign the image to some variable:
photoimage = PhotoImage(file='Sample1.png')
btn = Button(master=root,image=photoimage)
Related: Tkinter vanishing PhotoImage issue