How to disable the close or X button in Tkinter
Free Python Code

Free Python Code @freepythoncode

About: Programmer and content creator 😎

Joined:
Jul 18, 2023

How to disable the close or X button in Tkinter

Publish Date: Nov 24 '24
0 0

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

Comments 0 total

    Add comment