2010-06-03 1850 views
7

我有一個python程序,它打開一個新的窗口來顯示一些「關於」信息。這個窗口有它自己的關閉按鈕,我已經使它不可調整大小。然而,最大化和最小化的按鈕仍然存在,我希望它們消失。刪除Tkinter中的最小化/最大化按鈕

我正在使用Tkinter,包裝所有信息以顯示在Tk類中。

到目前爲止的代碼如下。我知道它並不漂亮,我計劃將信息擴展到一個類中,但我希望在移動之前先解決這個問題。

任何人都知道我可以如何管理窗口管理器顯示哪個默認按鈕?

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) 

回答

22

一般來說,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會刪除它們。

+2

謝謝。我最終使用overrideredirect方法並在底部框架中添加了一個脊。看起來不錯。 – Vidar 2010-06-05 11:11:15

+1

root.resizable(0,0)在Ubuntu中爲我工作,'使用tkinter – RahulArackal 2014-03-21 06:12:42

+1

@tzot root.overrideredirect(1)將完全隱藏外部框架。沒有關閉,最小或最大選項。如果執行了包含該行的代碼,那麼該窗口將一直卡在屏幕上,除非IDLE被關閉或操作系統關閉。 – Mohammed 2015-01-09 20:03:54

相關問題