删除 Tkinter 中的最小化/最大化按钮 [英] Removing minimize/maximize buttons in Tkinter

查看:195
本文介绍了删除 Tkinter 中的最小化/最大化按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 python 程序,它打开一个新窗口来显示一些关于"信息.这个窗口有它自己的关闭按钮,我已经把它设置为不可调整大小.但是,最大化和最小化它的按钮仍然存在,我希望它们消失.

I have a python program which opens a new windows to display some 'about' information. This window has its own close button, and I have made it non-resizeable. However, the buttons to maximize and minimize it are still there, and I want them gone.

我正在使用 Tkinter,将所有信息包装起来以显示在 Tk 类中.

I am using Tkinter, wrapping all the info to display in the Tk class.

到目前为止的代码如下.我知道它不漂亮,我计划将信息扩展到一个类中,但我想在继续之前解决这个问题.

The code so far is given below. I know its not pretty, and I plan on expanding the info making it into a class, but I want to get this problem sorted before moving along.

有人知道我如何控制 Windows 管理器显示的默认按钮吗?

Anyone know how I can govern which of the default buttons are shown by the windows manager?

def showAbout(self):


    if self.aboutOpen==0:
        self.about=Tk()
        self.about.title("About "+ self.programName)

        Label(self.about,text="%s: Version 1.0" % self.programName ,foreground='blue').pack()
        Label(self.about,text="By Vidar").pack()
        self.contact=Label(self.about,text="Contact: adress@gmail.com",font=("Helvetica", 10))
        self.contact.pack()
        self.closeButton=Button(self.about, text="Close", command = lambda: self.showAbout())
        self.closeButton.pack()
        self.about.geometry("%dx%d+%d+%d" % (175,\
                                        95,\
                                        self.myParent.winfo_rootx()+self.myParent.winfo_width()/2-75,\
                                        self.myParent.winfo_rooty()+self.myParent.winfo_height()/2-35))

        self.about.resizable(0,0)
        self.aboutOpen=1
        self.about.protocol("WM_DELETE_WINDOW", lambda: self.showAbout())
        self.closeButton.focus_force()


        self.contact.bind('<Leave>', self.contactMouseOver)
        self.contact.bind('<Enter>', self.contactMouseOver)
        self.contact.bind('<Button-1>', self.mailAuthor)
    else:
        self.about.destroy()
        self.aboutOpen=0

def contactMouseOver(self,event):

    if event.type==str(7):
        self.contact.config(font=("Helvetica", 10, 'underline'))
    elif event.type==str(8):
        self.contact.config(font=("Helvetica", 10))

def mailAuthor(self,event):
    import webbrowser
    webbrowser.open('mailto:adress@gmail.com',new=1)

推荐答案

一般来说,WM(窗口管理器)决定显示什么装饰不能由像 Tkinter 这样的工具包轻易决定.所以让我总结一下我所知道的加上我发现的:

In general, what decorations the WM (window manager) decides to display can not be easily dictated by a toolkit like Tkinter. So let me summarize what I know plus what I found:

import Tkinter as tk

root= tk.Tk()

root.title("wm min/max")

# this removes the maximize button
root.resizable(0,0)

# # if on MS Windows, this might do the trick,
# # but I wouldn't know:
# root.attributes(toolwindow=1)

# # for no window manager decorations at all:
# root.overrideredirect(1)
# # useful for something like a splash screen

root.mainloop()

还有一种可能性,对于除根窗口之外的 Toplevel 窗口,您可以执行以下操作:

There is also the possibility that, for a Toplevel window other than the root one, you can do:

toplevel.transient(1)

这将删除最小/最大按钮,但这也取决于窗口管理器.据我所知,MS Windows WM 确实删除了它们.

and this will remove the min/max buttons, but it also depends on the window manager. From what I read, the MS Windows WM does remove them.

这篇关于删除 Tkinter 中的最小化/最大化按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆