gpt4 book ai didi

Python - Tkinter - 通过双击鼠标切换/退出全屏图像

转载 作者:太空宇宙 更新时间:2023-11-04 05:03:19 25 4
gpt4 key购买 nike

我正在尝试编写将通过远程终端连接执行的代码。首先它会提示要使用的图像文件,然后全屏显示所述图像。我能够拼凑代码来实现这一目标。唯一的问题是我无法在不退出终端进程的情况下转义全屏图像。

我已经尽我所能地查看了所有地方,但似乎无法解决这种特殊情况。任何帮助将不胜感激,如果需要,我很乐意提供更多信息。 (我使用 Python 2.7 只是因为我引用的初始代码是 2.7)。

这是我目前所拥有的:

#!/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()

最佳答案

感谢您的帮助。最后,这是对我所引用的资源进行更多试验和错误的问题。包括我的后代最终代码,尽管我确信有更好的方法来做到这一点。

#!/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()

关于Python - Tkinter - 通过双击鼠标切换/退出全屏图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45136287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com