Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to disable tkinter Menu

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading