On some systems (like Linux) root.overrideredirect(True)
removes window manages (WM) which display border but WM also sends key/mouse events from system to your program. If WM doesn't send event then your program doesn't know that you clicked ESC.
This works for me on Linux Mint (based on Ubuntu and Debian).
Rasbian is base on Debian.
import tkinter as tk
def close_escape(event=None):
print("escaped")
root.destroy()
root = tk.Tk()
root.overrideredirect(True)
root.overrideredirect(False)
root.attributes("-fullscreen", True)
root.wm_attributes("-topmost", 1)
root.focus_set()
root.bind("<Escape>", close_escape)
root.after(5000, root.destroy) # close after 5s if `ESC` will not work
root.mainloop()
I put root.after(5000, root.destroy)
only for test - to close it after 5s if ESC
will not work.
I use close_escape
only to see if it was closed by ESC
or after()
. If code works then you can use root.bind("<Escape>", lambda event:root.destroy())
import tkinter as tk
root = tk.Tk()
root.overrideredirect(True)
root.overrideredirect(False)
root.attributes("-fullscreen", True)
root.wm_attributes("-topmost", 1)
root.focus_set()
root.bind("<Escape>", lambda event:root.destroy())
root.mainloop()
BTW: you may try also without root.overrideredirect()
- maybe it will works for you
import tkinter as tk
root = tk.Tk()
root.attributes("-fullscreen", True)
root.wm_attributes("-topmost", 1) # keep on top
#root.focus_set()
root.bind("<Escape>", lambda event:root.destroy())
root.mainloop()