Using .add() on the same widget more than once

Posted by Dillon Gilmore on Ask Ubuntu See other posts from Ask Ubuntu or by Dillon Gilmore
Published on 2012-06-23T21:03:54Z Indexed on 2012/06/23 21:24 UTC
Read the original article Hit count: 252

I asked this question on Reddit and was directed here. http://www.reddit.com/r/Ubuntu/comments/vhadl/quickly_dynamic_ui/

Unfortunately I am having the same issue and the problems seems that you can only use .add() on a widget once. So here is my code,

self.ui.labels = []
for titles in entries:
    label = Gtk.Label()
    self.ui.labels.append(label)         
    self.ui.viewport1.add(self.ui.labels[-1])
self.ui.paned1.show_all()

Now, for fun I decided "What would happen if I just manually did..."

self.ui.viewport1.add(Gtk.Label())
self.ui.viewport1.add(Gtk.Button())
self.ui.viewport1.add(Gtk.Entry())

For my first code snippet I get this error,

Gtk-CRITICAL **: gtk_viewport_add: assertion gtk_bin_get_child (bin) == NULL' failed

The error happens an unknown amount of times because the list entries can vary in length, but for my second code snippet it happens exactly twice. This means that when I viewport1.add() it works the first time, but all adds after that receive the error above.

So my question, is there a way in python to use .add() on the same widget more than once?

© Ask Ubuntu or respective owner

Related posts about application-development