Python Tkinter - How To Display JPG Image In Button
using python 2.7 and Tkinter, how can i make an image, that when clicked on runs a function? i was thinking about using something like Button(...,foto = 'mypic.jpg',command=myfunc)
Solution 1:
After looking around a bit, here's what I got. I haven't tested this, though.
from PIL import Image, ImageTk
image = 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.
Solution 2:
from PIL import Image, ImageTk
image = Image.open("mypic.jpg") photo = ImageTk.PhotoImage(image)
Button(...,image=photo,command=myfunc)
Post a Comment for "Python Tkinter - How To Display JPG Image In Button"