5

I would like the following program to quit on <Any-KeyPress> event.

from tkinter import *

root = Tk()
root.overrideredirect(True)
root.bind('<Any-KeyPress>', lambda e: root.destroy())
root.mainloop()

This works fine on Windows OS. However this does not work on Ubuntu unless I remove the line root.overrideredirect(True) from the above code.

Is this the intended behavior ?

Or is there a way whereby I can make my program to work while still using root.overrideredirect(True) ?

Edit


I just saw a similar question here at SO, where Bryan Oakley suggests using root.focus_force() but it does not help.

Edit 2


I used root.attributes('-fullscreen', True) instead of root.overrideredirect(True) as suggested here and that seems to work now.

j_4321
  • 15,431
  • 3
  • 34
  • 61
bhaskarc
  • 9,269
  • 10
  • 65
  • 86
  • Possible duplicate of [How to bind Tkinter destroy() to a key in Debian?](https://stackoverflow.com/questions/20287019/how-to-bind-tkinter-destroy-to-a-key-in-debian) – j_4321 Nov 27 '17 at 12:34

1 Answers1

0

Try this:

from tkinter import *

root = Tk()

root.bind('<Any-KeyPress>', quit())
root.mainloop()

Assuming that you want the program to quit, keep the code. If you just want to clear the screen, just use root.destroy() rather that quit(). Using root.overrideredirect(True) will NOT work on Ubuntu.

WarpPrime
  • 215
  • 5
  • 20