Python 删除Tkinter中的最小化/最大化按钮
我有一个python程序,它打开一个新窗口来显示一些“关于”的信息。此窗口有自己的关闭按钮,我已使其不可调整大小。但是,最大化和最小化的按钮仍然存在,我希望它们消失 我正在使用Tkinter,包装所有要在Tk类中显示的信息 目前为止的代码如下所示。我知道这并不漂亮,我计划将信息扩展到一个类中,但我想在继续之前解决这个问题 有人知道我如何控制windows管理器显示的默认按钮吗Python 删除Tkinter中的最小化/最大化按钮,python,windows,tkinter,Python,Windows,Tkinter,我有一个python程序,它打开一个新窗口来显示一些“关于”的信息。此窗口有自己的关闭按钮,我已使其不可调整大小。但是,最大化和最小化的按钮仍然存在,我希望它们消失 我正在使用Tkinter,包装所有要在Tk类中显示的信息 目前为止的代码如下所示。我知道这并不漂亮,我计划将信息扩展到一个类中,但我想在继续之前解决这个问题 有人知道我如何控制windows管理器显示的默认按钮吗 def showAbout(self): if self.aboutOpen==0: sel
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)
def展示(自我):
如果self.aboutpen==0:
self.about=Tk()
self.about.title(“about”+self.programName)
标签(self.about,text=“%s:Version 1.0”%self.programName,foreground='blue').pack()
标签(self.about,text=“By Vidar”).pack()
self.contact=标签(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+%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.reshable(0,0)
self.aboutpen=1
self.about.protocol(“WM_DELETE_WINDOW”,lambda:self.showAbout())
self.closeButton.focus\u force()的
self.contact.bind(“”,self.contactMouseOver)
self.contact.bind(“”,self.contactMouseOver)
self.contact.bind(“”,self.mailAuthor)
其他:
self.about.destroy()
self.aboutpen=0
def contactMouseOver(自身、事件):
如果event.type==str(7):
self.contact.config(字体=(“Helvetica”,10,“下划线”))
elif event.type==str(8):
self.contact.config(字体=(“Helvetica”,10))
def邮件作者(自我、事件):
导入网络浏览器
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)
这将删除最小/最大按钮,但也取决于窗口管理器。据我所知,微软视窗WM确实删除了它们
from tkinter import *
qw=Tk()
qw.resizable(0,0) #will disable max/min tab of window
qw.mainloop()
以下是在tkinter中禁用最大化和最小化选项的两种方法
请记住,图中显示的按钮代码不在示例中,因为这是有关如何使“最大/最小”选项卡不起作用或如何删除窗口的解决方案
对于windows,可以使用-toolwindow属性,如下所示:
root.attributes('-toolwindow', True)
from tkinter import *
from tkinter import ttk
window = Tk()
window.overredirect(True)
Button(window, text="x", command=window.destroy).pack()
window.mainloop()
所以,如果你想要完整的代码,就是这样
from tkinter import *
from tkinter import ttk
root = Tk()
root.attributes('-toolwindow', True)
root.mainloop()
其他window.attributes属性:
-alpha
-transparentcolor
-disabled
-fullscreen
-toolwindow
-topmost
重要注意事项这仅适用于Windows。不是马科斯
雨衣
使用mac,您可以使用overredirect属性和“x”按钮关闭窗口,这样就可以完成此任务了:我希望:
root.attributes('-toolwindow', True)
from tkinter import *
from tkinter import ttk
window = Tk()
window.overredirect(True)
Button(window, text="x", command=window.destroy).pack()
window.mainloop()
灵感来自
对我来说,它正在工作,我有一个Windows7
如果我有错误,请给我留言。谢谢。我最终使用了OverrideDirect方法,并在底部框架中添加了一个脊线。看起来还不错。root.resizable(0,0)在Ubuntu中对我有用,我使用tkinter@tzotoverrideredirect(1)将完全隐藏外部框架。关闭、最小或最大将没有选项。如果执行了包含此行的代码,则窗口将永远停留在屏幕上,除非重新排序空闲或关闭操作系统。root.attributes(toolwindow=1)此命令在Windows中不起作用。正确的命令是root.attributes(“-toolwindow”,1)。谢谢对于任何寻求更灵活的windows解决方案的人来说,这可能是有用的!只有最大化,最小化位于最左侧当前在使用Python 3的Windows上,
qw。可调整大小(0,0)
on禁用最大化按钮,但最小化按钮仍然有效。