Home > OS >  How to disable tkinter Menu
How to disable tkinter Menu

Time:12-17

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?

CodePudding user response:

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.

  • Related