njvb
njvb

Reputation: 1377

Controling button/hbox sizes in gtk

I am writing an app in python using getk and I've come across a problem. I am using an hbox to hold the buttons that go on my tool bar (new, open, save, etc) but the hbox seems to be expanding to take up a particular portion of the screen and the buttons are doing so as well making them really tall and ugly. How do I get them to stay at adecent size? I have already tried setting the expand and fill values to false and I can't find any methods to control the size of ether a button or an hbox. Here is the code for my new button:

img = gtk.Image()
img.set_from_stock(gtk.STOCK_NEW,gtk.ICON_SIZE_SMALL_TOOLBAR)
newButt = gtk.Button()
newButt.set_image(img)
newButt.show()
self.hBox4.pack_start(newButt, False, False, 0)

Upvotes: 3

Views: 7553

Answers (2)

appi2012
appi2012

Reputation: 218

You need to contain the entire HBox in a VBox, as follows:

main = gtk.VBox(False)
...
main.pack_start(self.hbox4, False)

The reason for this is that gtk allows for window resizing, so it doesn't allocate fixed heights and widths. By using a VBox, you are telling Gtk that I want the HBox to take up just as much space as it needs at the top of my window.

Hope that helps.

Upvotes: 3

Tarantula
Tarantula

Reputation: 19853

Child widgets will assume the allocation size that they parent widgets can give. You should set the size of the hbox or the button.

See here the size_request method of PyGTK to get more information.

Upvotes: 0

Related Questions