DEV Community

Free Python Code
Free Python Code

Posted on

How to disable the close or X button in Tkinter

code:

import tkinter as tk

root = tk.Tk()
root.geometry('200x200')

# create a function to close the window
def close_window():
    root.destroy()

close_bt = tk.Button(root, text = 'close', command = close_window)
close_bt.pack()

# create a function to disable close bt of the main window
def disable_close_bt():
    return

root.protocol('WM_DELETE_WINDOW', disable_close_bt)
root.mainloop()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)