到目前为止,我有一个命令可以使我的窗口全屏显示。现在,可以预见的是,我也希望能够退出全屏。
这是我的代码:
def toggFullscreen(self, win):
def exitFullscreen(event=None):
win.withdraw()
win.deiconify()
win.overrideredirect(False)
win.geometry('1024x700')
w = win.winfo_screenwidth()
h = win.winfo_screenheight()
win.overrideredirect(True)
win.geometry('%dx%d+0+0' % (w, h))
win.focus_set()
win.bind('<Escape>', exitFullscreen)
但问题是我无法让窗框重新出现。我认为执行 win.overrideredirect(False)
会起作用,但事实并非如此。
最佳答案
不确定为什么它无法在您的计算机上运行,但请尝试以下代码示例:
#!python3
import tkinter as tk
geom=""
def fullscreen():
global geom
geom = root.geometry()
w = root.winfo_screenwidth()
h = root.winfo_screenheight()
root.overrideredirect(True)
root.geometry('%dx%d+0+0' % (w, h))
def exitfullscreen():
global geom
root.overrideredirect(False)
root.geometry(geom)
root = tk.Tk()
tk.Button(root,text ="Fullscreen", command=fullscreen).pack()
tk.Button(root,text ="Normal", command=exitfullscreen).pack()
root.mainloop()
我要确保做的一件事是在进入全屏之前存储几何图形,然后在退出全屏时重新应用它。需要全局语句,因为如果我不使用它,fullscreen
函数会将几何图形存储在局部变量中,而不是我在顶部创建的变量中。
关于Python 3.x - 在 tkinter 中切换全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29986410/