Disable Exit (or [ X ]) in Tkinter Window

PythonTkinterServer Side ProgrammingProgramming

The window manager implements the Tkinter window control icons. To hide and show the Tkinter window control icons, we can use the built-in function, which describes whether we want to disable control icons’ functionality.

To disable the Exit or [X] control icon, we have to define the protocol() method. We can limit the control icon definition by specifying an empty function for disabling the state of the control icon.


#Import the tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of Tkinter frame
win= Tk()
#Define the geometry of the function
def close_win():
def disable_event():
#Create a button to close the window
btn = ttk.Button(win, text ="Click here to Close",command=close_win)
#Disable the Close Window Control Icon
win.protocol("WM_DELETE_WINDOW", disable_event)


The above code will display a window that has a disabled [X] window close control.

To close the window, click the button "Click here to Close."

Updated on 21-Apr-2021 07:41:25