Culky
Culky

Reputation: 43

In python how do i get the size (width,height) of a gtk label?

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

Upvotes: 1

Views: 1737

Answers (1)

zondo
zondo

Reputation: 20336

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.

Upvotes: 1

Related Questions