2013-01-10 55 views
4

在Python中試驗Gtk + 3。在網格中的Gtk滾動窗口大小

嘗試在滾動窗口容器內將「Gtk.TreeView」與輸入框一起添加到網格窗口。問題是滾動區域很小,因此幾乎看不到任何滾動窗口/ TreeView。下面是輸出的圖像:

enter image description here

相關的代碼是:

scroll = Gtk.ScrolledWindow() # Create scroll window 
scroll.add(self.MatchTree)  # Adds the TreeView to the scroll container 

grid = Gtk.Grid()    # Create grid container 
self.add(Grid)     # Add grid to window (self) 
Grid.add(scroll)     # Add scroll window to grid 
Grid.attach_next_to(self.Entry, scroll, Gtk.PositionType.BOTTOM, 1, 1) # Attach entry to bottom of grid. 

那麼如何控制滾動區域的大小?

乾杯, 菲爾

回答

6

你需要做的是將GtkScrolledWindowhexpandvexpand屬性設置爲True。爲此,您可以在創建對象是這樣的:

scroll = Gtk.ScrolledWindow(hexpand=True, vexpand=True) 

如果你到它,我建議你使用Glade工作程序的界面,這讓很多簡單的工作出了這種問題,因爲你可以輕鬆訪問所有小部件屬性。

+0

太好了,謝謝你的建議。我試過格萊德,但認爲這只是另一個關於我仍然試圖抓住的話題的抽象層次。但是在向用戶展示所有選項方面你是對的。我會牢記這一點! –

+1

我明白了,有時候最好先從事手工操作以瞭解如何更好地使用它。儘管如此,當你發現你寫的東西不能按照你的意圖工作時,你可以使用Glade來測試不同的屬性組合,以使其工作(事實上,這就是我發現你的代碼問題:) – asermax