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.
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.
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: [email protected]",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:[email protected]',new=1)
To remove maximize button we have to set the MaximizeBox property to false of the windows form. Now when you open the windows form you will notice the windows form's maximize button is in disable mode as well as if user double-click on the title bar it will not maximize the windows form.
It is a standard Python interface to the Tk GUI toolkit shipped with Python. To create a Frameless window, we will use the overrideredirect() method. Syntax: root.overrideredirect(value) To create a Frameless Window, we will pass value True or 1 as arguments in over ride redirect() method.
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()
There is also the possibility that, for a Toplevel
window other than the root one, you can do:
toplevel.transient(1)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With