Python 3.x - 在 tkinter 中切换全屏

标签 python tkinter toggle fullscreen

到目前为止,我有一个命令可以使我的窗口全屏显示。现在,可以预见的是,我也希望能够退出全屏。

这是我的代码:

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/

相关文章:

python - Python Socket编程更改服务器套接字

Python:无法使用 SSL 套接字发出 HTTPS 请求

python - 如何将 Tkinter 与 Python 登录屏幕集成?

python - 在 tkinter 中使用选项菜单小部件时出错

jQuery 用简单的代码选择所有具有相同类的内容?

jquery - 按 ID 显示/隐藏/切换多个 Div?

javascript - 添加幻灯片切换

python - Python Partial String Comparison 需要 String Comparison 的解决方案

python - 从 parent 实例化 child

python-3.x - tkinter 网格不根据窗口大小调整大小