我正在 python 中使用 Tkinter 构建一个简单的登录系统,因为我需要一个不可调整大小的,它可以通过“可调整大小(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 按钮。我给出了仅删除最大化的示例,然后为两者都删除了一个示例。
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()
使用 root.wm_attributes('-type', '工具栏')