Python – Which GTK widget combination to use for scrollable column of widgets


I'm working with PyGTK, trying to come up with a combination of widgets that will do the following:

  • Let me add an endless number of widgets in a column
  • Provide a vertical scrollbar to get to the ones that run off the bottom
  • Make the widgets' width adjust to fill available horizontal space when the window is resized

Thanks – I'm new to GTK.

Best Solution

  • An endless number of widgets in a column: Sounds like a GtkVBox.
  • Vertical scrollbar: Put your VBox in a GtkScrolledWindow.
  • Horizontal stretching: This requires setting the appropriate properties for the VBox, ScrolledWindow, and your other widgets. At least in Glade the defaults seem to mostly handle this (You will probably want to change the scrollbar policy of the ScrolledWindow).

Now for the trick. If you just do what I've listed above, the contents of the VBox will try to resize vertically as well as horizontally, and you won't get your scrollbar. The solution is to place your VBox in a GtkViewport.

So the final hierarchy is ScrolledWindow( Viewport( VBox( widgets ) ) ).

Related Question