I want to show a GUI to client, but I don't want to give the possibility to the client to close the window through the [X]
button.
How do I disable, hide or remove the close [X]
button of Tkinter window?
I found the following answers:
However, these posts are not answering my question. I want to disable, hide or completely remove the [X]
button.
When I use protocol
:
def __init__(self):
Frame.__init__(self, bg = "black")
self.protocol('WM_DELETE_WINDOW', self.doSomething)
self.pack(expand = 1, fill = BOTH)
def doSomething(self):
if showinfo.askokcancel("Quit?", "Are you sure you want to quit?"):
self.quit()
I receive the following error:
self.protocol('WM_DELETE_WINDOW', self.doSomething)
AttributeError: 'GUI' object has no attribute 'protocol'
The problem with calling the protocol
method is that it's a method on a root window but your GUI object is not a root window. Your code will work if you call the protocol method on the root window.
As for how to remove the button completely -- there's no method to simply remove that one button. You can remove all of the window manager buttons and frame by setting the overrideredirect
flag.