我有一个 python 程序可以打开一个新窗口来显示一些“关于”信息。这个窗口有自己的关闭按钮,而且我已经把它设为不可调整大小。但是,最大化和最小化它的按钮仍然存在,我希望它们消失。
我正在使用 Tkinter,包装所有信息以显示在 Tk 类中。
到目前为止的代码如下。我知道它不太好,我计划将信息扩展到一个类中,但我想在继续之前解决这个问题。
有人知道我如何控制 Windows 管理器显示哪些默认按钮吗?
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 这样的工具包轻易决定。那么让我总结一下我所知道的以及我发现的:
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
窗口而不是根窗口,您可以:
toplevel.transient(1)
这将删除最小/最大按钮,但这也取决于窗口管理器。据我了解,MS Windows WM 确实删除了它们。
关于python - 删除 Tkinter 中的最小化/最大化按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2969870/