Here's one with built in tkinter GUI package (I wrote using python 3.7.2)
Get the image here: https://developers.google.com/speed/webp...y/4.sm.jpg
convert to 4.sm.png using gimp export as 4.sm.png (create images directory below script, and save there)
you will need to install pillow (which contains PIL), use:
when clicked (5 times):
Get the image here: https://developers.google.com/speed/webp...y/4.sm.jpg
convert to 4.sm.png using gimp export as 4.sm.png (create images directory below script, and save there)
you will need to install pillow (which contains PIL), use:
pip install pillow
# Note requires python 3, written with 3.7.2 # download image here: https://developers.google.com/speed/webp/gallery/4.sm.jpg # convert to png with gimp # create images directory in script path import tkinter as tk import os from pathlib import Path import PIL class ImageClick: def __init__(self, parent=None): # Make sure path is known (assures path set to this script directory) os.chdir(os.path.abspath(os.path.dirname(__file__))) # set image path imagepath = Path('./images') photo = imagepath / '4.sm.png' if not parent: self.parent = tk.Tk() else: self.parent=parent photo=tk.PhotoImage(file=photo) btn = tk.Button(self.parent) btn.config(image=photo, width="320", height="241", activebackground="black", bg="black", bd=0, command=self.clicked) btn.pack(fill=tk.BOTH) parent.mainloop() def clicked(self): print('You clicked me') if __name__ == '__main__': root = tk.Tk() ImageClick(root) root.mainloop()Looks like:
when clicked (5 times):
Output:You clicked me
You clicked me
You clicked me
You clicked me
You clicked me