2014-02-16 49 views
1

我想調整我的GUI中的一個窗口,但我的一個框架被排除在外,我不知道爲什麼。窗口水平調整大小,但是當我嘗試垂直調整大小時,按鈕消失。這是我的第一個GUI,所以我敢肯定有我丟失的東西...Python tkinter:問題調整框架

from Tkinter import * 
from ttk import * 

class GUI(Frame): 
    def __init__(self, root): 
     Frame.__init__(self, root) 

     self.root = root 

     lbFrame = Frame(self.root) 
     nbFrame = Frame(self.root) 

     self.note = Notebook(nbFrame) 
     self.note.pack(fill=BOTH, expand=YES) 

     lbFrame.pack(side=LEFT, fill=BOTH, expand=YES) 
     nbFrame.pack(side=RIGHT, fill=BOTH, expand=YES) 

     self.make_file_viewer() 

     # Label 
     lblabel = Label(lbFrame, text='Files', background='#E8E8E8') 
     lblabel.pack(side=TOP, expand=YES, padx=10, pady=10) 

     # Listbox 
     self.lb = Listbox(lbFrame, height=49, borderwidth=0, font=('Purisa', 11), selectmode=EXTENDED) 
     self.lb.pack(side=BOTTOM, expand=YES, padx=10, pady=10) 

    def make_file_viewer(self): 
     fvwr = Frame(self.note) 

     dataFrm = Frame(fvwr) 
     btnFrm = Frame(fvwr) 
     dataFrm.pack(side=TOP, fill=BOTH, expand=YES) 
     btnFrm.pack(side=BOTTOM, fill=BOTH, expand=YES) 

     fvwr.config(borderwidth=2) 
     self.note.add(fvwr, text='File View') 

     # Label 
     self.lbl_fvwr_search = Label(dataFrm, text='Search Hits\t0', justify=LEFT) 
     self.lbl_fvwr_search.pack(side=TOP, anchor=W, expand=YES) 

     # Scrollbar 
     scrollbar_fvwr = Scrollbar(dataFrm) 
     scrollbar_fvwr.pack(side=RIGHT, fill=Y, expand=YES) 

     # Textbox 
     self.outputPanel_fvwr_text = Text(dataFrm, wrap='word', height=40, width=115, yscrollcommand=scrollbar_fvwr.set) 
     self.outputPanel_fvwr_text.pack(side=LEFT, fill=BOTH, expand=YES) 
     scrollbar_fvwr.config(command=self.outputPanel_fvwr_text.yview) 

     # Start button 
     viewBtn = Button(btnFrm, text='Start', width=8) 
     viewBtn.pack(anchor=W, expand=YES) 

if __name__ == '__main__': 
    root = Tk() 
    app = GUI(root) 
    root.mainloop() 

回答

5

你可以做的絕對最好的辦法是重新開始,並一步一步的做你的佈局。首先創建主要區域,並確保它們正確調整大小。在你的情況下,創建左側和右側。再次,讓雙方適當調整彼此的關係。

一旦你完成了,重點放在一個部分。既然你知道主要部分調整正確,你只需要關注該特定部分內的元素。再次,將它分解成碎片,並在處理主要碎片內的任何小部件之前使這些碎片工作。

當你這樣做你的佈局,它是很多更容易讓整個圖形用戶界面工作正常,因爲你沒有試圖一次處理六個小部件的行爲。

在您的具體情況下,問題的根源在於您幾乎擁有expand=YES。作爲一般的經驗法則,您只需要在給定的父窗口中將其設置爲YES。例如,在您的主窗口中,您希望擴展權限,但不是左側(我猜測),並且在右側窗口中您希望文本小部件展開,而不是其他小部件。

設置爲expand=NOscrollbar_fvwr,self.lbl_fvwr_searchbtnFrm以正確調整右側的大小。對於左側,爲self.lb添加fill=BOTH,爲lblabel添加expand=NONE

+0

謝謝!這真的有幫助!我喜歡你的評論,但這是我的第一個問題,我還沒有名聲。再次感謝 – rhowe