1

I have looked all over for this but can't find an answer that works.

element.get_allocation().y returns -1
element.get_allocation().height returns 1

This is the code im using to create the label

item_link_summary = Gtk.Label(item_summary)
item_link_summary.show()
self.layout1.put(item_link_summary, 0, top)
print item_link_summary.get_allocation().y
Culky
  • 43
  • 4
  • 3
    Although you called `show`, you can't get the size until the widget has been both realized and laid out. See http://stackoverflow.com/questions/2675514/totally-fed-up-with-get-gtk-widget-height-and-width – user4815162342 Nov 15 '12 at 21:31

1 Answers1

1

If you want to know how much space the label requires, you can use the size_request method, which returns a tuple (width, height). If you want to know how much space it is being given, you have to wait until it is realized. This means until it and all of its ancestors, including the toplevel window, are shown. Usually that means after window.show_all() is executed. After that, you can use label.get_allocation().width and label.get_allocation().height.

zondo
  • 19,901
  • 8
  • 44
  • 83