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'v开发者_运维知识库e 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
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)
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())
精彩评论