Home > OS >  How to remove/disable the minimize button in Tkinter without removing/disabling the close button
How to remove/disable the minimize button in Tkinter without removing/disabling the close button

Time:04-09

I am building a simple login system using Tkinter in python, for that I need a non-resizable and it can be done by 'resizable(0,0) but it only disables the maximize button. But I what the minimize button to be disabled also, so please someone help me find the solution for these.

Here's the sample of my code,

from tkinter import *

root = Tk()
root.geometry("400x300")


def signIn():

    # Opening a new window for SignIn options
    signin = Toplevel()
    signin.grab_set()
    signin.focus_set()

    # I also tried this but it removes the whole title bar along with the close 'X' button
    # root.overrideredirect(True)

# SignIn button
button = Button(root, text="Sign In", command=signIn)
button.grid(row=1, column=0)

root.mainloop() 

CodePudding user response:

from tkinter import *

root = Tk()
root.geometry("400x300")
root.attributes('-toolwindow', True)

def signIn():

    # Opening a new window for SignIn options
    signin = Toplevel()
    signin.grab_set()
    signin.focus_set()

    # I also tried this but it removes the whole title bar along with the close 'X' button
    # root.overrideredirect(True)

# SignIn button
button = Button(root, text="Sign In", command=signIn)
button.grid(row=1, column=0)

root.mainloop()

CodePudding user response:

If you want to disable the minimize and maximize use this. It will leave you with only the x button. I gave example for only removing maximize and then one for both.

import tkinter as tk
import time



root = tk.Tk()
root.geometry("500x500")
root.resizable(False, False)#removes only the maximize option

root.attributes("-toolwindow", True)#removes both the maximize and the minimize option


root.mainloop()
  • Related