tags:

views:

13

answers:

1

In PyGTK what is the easiest way to figure out the dimensions of a widget? I know that it is easy to do with the gtk.Window object, but I can't find in the reference manual any way to get dimensions for the other objects.

Any help is greatly appreciated thanks :D

+1  A: 

You may be looking for the get_allocation method:

The get_allocation() method returns a gtk.gdk.Rectangle containing the bounds of the widget's allocation.

or size_request:

The size_request() method returns the preferred size of a widget as a tuple containing its required width and height. This method is typically used when implementing a gtk.Container subclass to arrange the container's child widgets and decide what size allocations to give them with the size_allocate() method. Obtaining a size request requires that the widget be associated with a screen, because font information may be needed.

Also remember that the size request is not necessarily the size a widget will actually be allocated.

The latter is what the widget would like to have as its size (given font information), the former what it's actually given by its container when it lays out the widgets.

Alex Martelli