How to disable tkinter Menu

Question:

This is my code below. I want a tkinter window which does not have option to close at the top right. It should either be hidden or disabled. I tried multiple things online but it was all in vein. If someone could help, will be very glad. Thank You.

class RegisterClass(SendOtp):
    
        def __init__(self):
            super().__init__()
            self.window = Tk()
            self.window.title("Register")
            self.window.geometry("925x500+300+200")
            self.window.configure(bg="#fff")
            self.window.resizable(False, False)

edit:
I got self.window.overrideredirect(1) which could completely remove the above menu bar but it just looks ugly. Anything I could just disable the buttons and not completely vanish them?

Asked By: Dilip

||

Answers:

Way one overrideredirect

This will hide the whole top bar of the tkinter window.

from tkinter import *
class RegisterClass(SendOtp):
    
        def __init__(self):
            super().__init__()
            self.window = Tk()
            self.window.title("Register")
            self.window.overrideredirect(True)
            self.window.geometry("925x500+300+200")
            self.window.configure(bg="#fff")
            self.window.resizable(False, False)


Way two wm_protocol

Here whenever the user clicks X self.onClosing function execute.

from tkinter import *
class RegisterClass(SendOtp):
    
        def __init__(self):
            super().__init__()
            self.window = Tk()
            self.window.title("Register")
            self.window.geometry("925x500+300+200")
            self.window.configure(bg="#fff")
            self.window.wm_protocol("WM_DELETE_WINDOW", self.onClosing)
            self.window.resizable(False, False)
    def onClosing(self):
        pass
        # Write your code for what you want whenever the user clicks the `X` button. # self.window.destroy() for closing the window if you want.

Answered By: codester_09
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.