如何在不删除/禁用关闭按钮的情况下删除/禁用Tkinter中的最小化按钮



我正在python中使用Tkinter构建一个简单的登录系统,为此我需要一个不可调整大小的,可以通过'resizable(0,0(来完成,但它只禁用最大化按钮。但是我的最小化按钮也被禁用了,所以请有人帮我找到这些的解决方案。

这是我的代码示例

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() 
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()

如果您想禁用最小化和最大化,请使用此。它只会给你留下x按钮。我举了一个例子,只去掉maximum,然后两者都去掉一个。

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()

最新更新