0

I am working on a project using Tkinter library for making a GUI. This GUI will be displayed on a touch screen using raspberry pi 3.

I want to prevent user from exiting or minimising the program. Is there any way to disable or remove the title bar? Or is there a better way to achieve this?

baduker
  • 19,152
  • 9
  • 33
  • 56
Yasser Daif
  • 11
  • 1
  • 2

2 Answers2

4

Since you mentioned a raspberry pi I suppose you are using Linux. In this case you can use root.attributes('-type', 'dock') (assuming your Tk instance is called root). This way, your window will have no decoration (so no close or minimize buttons) and will be always on top. If you don't want it always on top, you can use type 'splash' instead. In any case, you will need to use focus_force to be able to get keyboard focus.

import tkinter as tk

root = tk.Tk()
root.attributes('-type', 'dock')
root.geometry('200x200')
tk.Entry(root).pack()
root.focus_force()
root.mainloop()

Otherwise, you can prevent the window from being closed by setting the 'WM_DELETE_WINDOW' protocol and redisplay the window each time it is minimized:

import tkinter as tk

root = tk.Tk()

def unmap(event):
    if event.widget is root:
        root.deiconify()

root.protocol('WM_DELETE_WINDOW', lambda: None)  # prevent closing
root.bind('<Unmap>', unmap)  # redisplay window when it's minimized

root.mainloop()
j_4321
  • 15,431
  • 3
  • 34
  • 61
0
root = tk.Tk()
root.wm_attributes('-type', 'splash')

For more details go to this link: Remove titlebar without overrideredirect() using Tkinter?

Devansh Soni
  • 771
  • 5
  • 16
Devdatt
  • 82
  • 5