Clickable Images for Python -


i'm entry level python coder looking create guess styled game. @ university, i've yet learn how import images , bind them fixed places on screen (resembling game board). there way click on specific image , have onclickevent occur, specific character(image) chosen. majority of coding abilities in python, skeptical if best possible language project in.

every gui has button widget clicable , (mostly) can display image.

but in gui can assign click event every object ie. label image.

ie. tkinter

import tkinter tk pil import image, imagetk  # --- functions ---  def on_click(event=none):     # `command=` calls function without argument     # `bind` calls function 1 argument     print("image clicked")  # --- main ---  # init     root = tk.tk()  # load image image = image.open("image.png") photo = imagetk.photoimage(image)  # label image l = tk.label(root, image=photo) l.pack()  # bind click event image l.bind('<button-1>', on_click)  # button image binded same function  b = tk.button(root, image=photo, command=on_click) b.pack()  # button text closing window b = tk.button(root, text="close", command=root.destroy) b.pack()  # "start engine" root.mainloop() 

graphic modules pygame can display image too, , have click event have check manually if clicked in area image (and have create mainloop manually)


Comments

Popular posts from this blog

Formatting string according to pattern without regex in php -

c - zlib and gdi32 with OpenSSL? -

java - inputmismatch exception -