Question

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.

Was it helpful?

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 ) ) ).

OTHER TIPS

What Steve said in code:

vbox = gtk.VBox()
vbox.pack_start(widget1, 1, 1) ## fill and expand
vbox.pack_start(widget2, 1, 1) ## fill and expand
vbox.pack_start(widget3, 1, 1) ## fill and expand
swin = gtk.ScrolledWindow()
swin.add_with_viewport(vbox)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top