2

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 was able to piece together the code to make this happen. Only problem is I can't escape the fullscreen image without quitting the process in the terminal.

I've looked everywhere I can and can't seem to work out this particular situation. Any help would be greatly appreciated and I'm happy to provide more information if needed. (I'm using Python 2.7 only because the initial code I referenced was 2.7).

Here is what I have so far:

#!/usr/bin/env python

from Tkinter import *
from PIL import Image, ImageTk

def choose_picture():
    user_input = raw_input("Choose picture file: ")
    user_input = (user_input + ".jpg")

    root = Tk()
    main_image = Image.open(user_input)  # Room label image
    photo = ImageTk.PhotoImage(main_image)
    Label(root, image=photo).pack()
    root.attributes('-fullscreen', True)
    root.mainloop()

choose_picture()
jimmyscrote
  • 41
  • 1
  • 3
  • how do you expect to close, or minimize it, from keyboard or mouse ? it may require an event binding, another solution is to expand the window to the screen resolution, to keep the standard buttons available, you can find some posts here – PRMoureu Jul 17 '17 at 05:23
  • 2
    [Have you seen this answer ?](https://stackoverflow.com/a/23840010/1189040) – Himal Jul 17 '17 at 05:24

1 Answers1

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()
jimmyscrote
  • 41
  • 1
  • 3