如何在 Tkinter 中删除/禁用最小化按钮而不删除/禁用关闭按钮

问题描述 投票:0回答:3

我正在 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() 
python python-3.x tkinter tkinter-entry tkinter-layout
3个回答
1
投票
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()


1
投票

如果您想禁用最小化和最大化,请使用此功能。它将只剩下 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()

0
投票

使用 root.wm_attributes('-type', '工具栏')

© www.soinside.com 2019 - 2024. All rights reserved.