Python - Tkinter - Toggle/quit Fullscreen Image With Double Mouse Click
I am trying to write code that would be executed through a remote terminal connection. First it would prompt for the image file to be used, then display said image fullscreen. I wa
Solution 1:
Thanks for the help. In the end, it was a matter of more trial and error with the resources I was referencing. Including my final code for posterity, though I'm sure there's a better way to do it.
#!/usr/bin/env python
from Tkinter import *
from PIL import Image, ImageTk
"""Asks for picture file. Loads picture file with '.jpg' appended to name entered.
Double Click and F11 both resume fullscreen.
Triple Click and Escape both close fullscreen."""
def choose_picture():
user_input = raw_input("Choose picture file: ")
user_input = (user_input + ".jpg")
root = Tk()
root.state = True
root.attributes("-fullscreen", True)
main_image = Image.open(user_input) # Room label image
photo = ImageTk.PhotoImage(main_image)
Label(root, image=photo).pack()
def resume_fullscreen(self, event=None):
root.state = True
root.attributes("-fullscreen", True)
return "break"
def end_fullscreen(self, event=None):
root.state = False
root.attributes("-fullscreen", False)
root.geometry("200x200")
return "break"
root.bind("<Double-1>", resume_fullscreen)
root.bind("<Triple-1>", end_fullscreen)
root.bind("<F11>", resume_fullscreen)
root.bind("<Escape>", end_fullscreen)
root.mainloop()
choose_picture()
Post a Comment for "Python - Tkinter - Toggle/quit Fullscreen Image With Double Mouse Click"