Python 3.x - 进入tkin全屏模式切换

2024-10-01 17:39:34 发布

您现在位置:Python中文网/ 问答频道 /正文

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

这是我的代码:

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)会有用,但事实并非如此。在


Tags: 代码命令selfnoneeventfalsedefwin
2条回答

在调用withdrawdeiconify之前,更改overrideredirect标志。在

不确定它在您的计算机上不起作用的原因,但请尝试以下代码示例:

#!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函数将几何图形存储在局部变量中,而不是我在顶部创建的变量中。在

相关问题 更多 >

    热门问题