2017-09-29 3 views
1

버튼이있는 다른 프레임 위에있는 프레임 안에 트리 뷰가 있습니다. 창 크기를 조정할 때 위쪽 프레임을 확장하고 싶지만 단추 프레임을 그대로 유지하면됩니다. 파이썬 2.7.5에서Tkinter/ttk를 사용하여 다른 위젯을 잠그는 동안 수직 위젯 하나를 확장하십시오.

코드 :

class MyWindow(Tk.Toplevel, object): 
     def __init__(self, master=None, other_stuff=None): 
     super(MyWindow, self).__init__(master) 
     self.other_stuff = other_stuff 
     self.master = master 
     self.resizable(True, True) 
     self.grid_columnconfigure(0, weight=1) 
     self.grid_rowconfigure(0, weight=1) 

     # Top Frame 
     top_frame = ttk.Frame(self) 
     top_frame.grid(row=0, column=0, sticky=Tk.NSEW) 
     top_frame.grid_columnconfigure(0, weight=1) 
     top_frame.grid_rowconfigure(0, weight=1) 
     top_frame.grid_rowconfigure(1, weight=1) 

     # Treeview 
     self.tree = ttk.Treeview(top_frame, columns=('Value')) 
     self.tree.grid(row=0, column=0, sticky=Tk.NSEW) 
     self.tree.column("Value", width=100, anchor=Tk.CENTER) 
     self.tree.heading("#0", text="Name") 
     self.tree.heading("Value", text="Value") 

     # Button Frame 
     button_frame = ttk.Frame(self) 
     button_frame.grid(row=1, column=0, sticky=Tk.NSEW) 
     button_frame.grid_columnconfigure(0, weight=1) 
     button_frame.grid_rowconfigure(0, weight=1) 

     # Send Button 
     send_button = ttk.Button(button_frame, text="Send", 
     command=self.on_send) 
     send_button.grid(row=1, column=0, sticky=Tk.SW) 
     send_button.grid_columnconfigure(0, weight=1) 

     # Close Button 
     close_button = ttk.Button(button_frame, text="Close", 
     command=self.on_close) 
     close_button.grid(row=1, column=0, sticky=Tk.SE) 
     close_button.grid_columnconfigure(0, weight=1) 

나는 이런 식으로 다른 인스턴스를 만들 :

내가 시도 무엇
window = MyWindow(master=self, other_stuff=self._other_stuff) 

: 에만 버튼이 사라 만든 사이즈 변경 잠금 시도. 나는 또한 주변의 변화하는 무게를 시도했지만 현재의 구성은 모든 것이 화면에 나타나는 유일한 방법이다.

항상 상관없이 어떻게 보일지 얼마나 높이 : 사전에 enter image description here

감사 : 나는 것을 방지하려면 무엇 When it first launches

.

답변

3

문제는 단추 프레임이 커지는 것이 아니라 위쪽 프레임이 커지지만 모든 공간을 사용하지 않는 것입니다. 이는 행 1에 top_frame의 가중치가 1이지만 행 1에 아무 것도 넣지 않았기 때.에 여분의 공간이 행의 1의 행으로 할당되지만 행 1은 비어 있기 때.입니다.

쉽게 시각화하려면 top_frame을 tk (ttk가 아닌) 프레임으로 변경 한 다음 일시적으로 고유 한 배경색을 지정하십시오. 창 크기를 조정하면 top_frame이 전체적으로 창을 채우지 만 부분적으로 비어 있음을 알 수 있습니다.

이 같은 top_frame 만들기 : 창 크기를 조정할 때

top_frame = Tk.Frame(self, background="pink") 

...는 다음 이미지와 같은 화면을 얻을 수 있습니다. 핑크색 top_frame이 표시되고, button_frame이 바람직한 크기로 유지됩니다.

screenshot showing colored empty space

당신은 단순히이 코드 한 줄을 제거하여이 문제를 해결할 수 있습니다 : 당신은 어떤 더 나은 것을 설명 할 수 없었다

top_frame.grid_rowconfigure(1, weight=1) 
+1

. 그리드에 대해 더 잘 이해하고 어떻게 작동하는지, 감사합니다! – vaponteblizzard

관련 문제