【问题标题】:python tkinter overrideredirect; cannot receive keystrokes (Linux)python tkinter 覆盖重定向;无法接收击键(Linux)
【发布时间】:2011-08-18 16:20:36
【问题描述】:

我有一个 python tkinter 应用程序,我想全屏运行。当我取消注释 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::or 包,它应该可以解决这个错误。我将如何安装它,是否可以在我的 python 应用程序中使用它?

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

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

【问题讨论】:

标签: python tkinter


【解决方案1】:

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

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

【讨论】:

  • “全屏”与设置 overrideredirect 属性不同。
  • 如果您使用 overrideredirect()-fullscreen 来全屏显示,请注意:前者应该包含整个“显示” - 所有显示器,包括可能不在任何显示器上的区域, 与完整屏幕截图相同的区域。后者只接管它所在的屏幕 - 所以通常是一台显示器。
【解决方案2】:

您可能希望在执行绑定时输入可调用的self.root.quit 而不是self.root.quit() 以避免调用该函数。当您按下 Escape 时,将使用事件参数调用可调用对象(我知道我知道)。如果self.root.quit() 不接受任何参数:使用 lambda:self.root.bind('&lt;Escape&gt;',lambda e:self.root.quit())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-12
    • 2016-07-28
    • 1970-01-01
    • 2013-02-22
    • 2018-01-01
    • 1970-01-01
    • 2015-06-18
    • 2014-12-28
    相关资源
    最近更新 更多