Python Tkinter - How to display JPG image in Button Python Tkinter - How to display JPG image in Button tkinter tkinter

Python Tkinter - How to display JPG image in Button


After looking around a bit, here's what I got. I haven't tested this, though.

from PIL import Image, ImageTkimage = Image.open("mypic.jpg")photo = ImageTk.PhotoImage(image)Button(...,image=photo,command=myfunc)

The foto should be image here. PIL is a dependency you have to obtain. Hope this helps.


from PIL import Image, ImageTk

image = Image.open("mypic.jpg")photo = ImageTk.PhotoImage(image)

Button(...,image=photo,command=myfunc)