python tkinter overrideredirect; cannot receive keystrokes (Linux)
Asked Answered
P

2

4

I have a python tkinter application which I want to run full screen. When I uncomment overrideredirect, the window manager (Gnome, Linux) will not be able to forward keystrokes to the application anymore.

(fragment, 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)

I've found the window::or package for Tcl/Tk, which is supposed to resolve this bug. How would I go about installing this, and would it be possible to use it from within my python application?

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

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

Priscian answered 4/5, 2011 at 15:53 Comment(1)
some info here: wiki.python.org/moin/How%20Tkinter%20can%20exploit%20Tcl/…Maggiore
M
4

This works for the use case where you're using overrideredirect to get fullscreen, which is somewhat common:

#self.root.overrideredirect(1)
self.root.attributes('-fullscreen', True)
Maraud answered 25/11, 2012 at 20:53 Comment(2)
"fullscreen" isn't the same as setting the overrideredirect attribute.Raceway
Heads-up if you're using overrideredirect() or -fullscreen to go full-screen: the former should encompass the entire "display" - all monitors including areas that might not be on any monitor, same area that is captured with a full screenshot. The latter only takes over the screen it's on - so normally one monitor.Wellhead
D
0

You might want to enter the callable self.root.quit instead of self.root.quit() when you do the binding to avoid calling the function. when you will press Escape the callable will be called (I know I know) with an event argument. If self.root.quit() does not accept any argument: use lambda: self.root.bind('<Escape>',lambda e:self.root.quit())

Delaney answered 20/4, 2015 at 12:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.