2

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:

  1. Python Tkinter “X” button control
  2. Removing minimize/maximize buttons in Tkinter

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'

Community
  • 1
  • 1
Zeb
  • 2,687
  • 7
  • 28
  • 36
  • 1
    What OS are you using? I believe it is OS specific. In most cases you can close window just by pressing Alt+F4 even if there was no X button. – mlt Jan 31 '14 at 21:32
  • I'm using Ubuntu 13.04 – Zeb Jan 31 '14 at 21:33
  • [This might be relevant](http://askubuntu.com/questions/182914/how-to-disable-closing-a-window). It is not so pythonic question *per se*. – mlt Jan 31 '14 at 21:39
  • 2
    Note that the example you link is using `root.protocol`, like in [TkInter's documentation](http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm). I guess your `GUI` class is not the root window. – Ricardo Cárdenes Jan 31 '14 at 21:56
  • I define class like class myClass(Frame): , I define above code in this class , so this is act as my root class – Zeb Jan 31 '14 at 22:33

1 Answers1

2

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.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685