python tkinter overrideredirect;无法接收击键(Linux)

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

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

我有一个pythontkinter应用程序,我想全屏运行。当我取消对overrideredirect的注释时,窗口管理器(Gnome,Linux)将无法再将击键操作转发到应用程序。在

(碎片,Python)

# make it cover the entire screen
w, h = master.winfo_screenwidth(), master.winfo_screenheight()
self.root.geometry("%dx%d+0+0" % (w, h))
self.root.focus_set() # <-- move focus to this widget
self.root.bind('<Escape>', self.root.quit())
#self.root.overrideredirect(True)

我找到了Tcl/Tk的window::或包,它应该可以解决这个bug。我该如何安装它,以及在python应用程序中使用它吗?在

http://www.binarism.com/tk/window/or/

http://www.binarism.com/tk/window-or-0.1.1.tgz


Tags: orselfmastercom应用程序httpwwwroot
2条回答

在进行绑定以避免调用函数时,可能需要输入可调用的self.root.quit,而不是{}。当您按下Escape键时,callable将被调用(我知道我知道)一个事件参数。如果self.root.quit()不接受任何参数:请使用lambda:self.root.bind('<Escape>',lambda e:self.root.quit())

这适用于使用overrideredirect获得全屏显示的用例,这有点常见:

#self.root.overrideredirect(1)
self.root.attributes('-fullscreen', True)

相关问题 更多 >

    热门问题