Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Glade to design a Box with widgets and then load these widgets into my UI at run-time. To create each Box with widgets at run-time, I create a new GtkBuilder, call add_from_string passing in the text from the .ui file Glade creates, and then use the object returned from get_object("box1") in the UI. I know I could create the widgets with code, but for now, I'd like to use the .ui files Glade creates. It seems inefficient though to instantiate a new GtkBuilder object and the wasted Window object for every Box I want to create. Is there a more efficient method to load .ui files without creating a new GtkWidget object and wasted Window object?

Thanks, Vance

share|improve this question

If you want to fill up your GUI with new widgets while your app is running, it is completely wrong to create a bunch of separate .ui files and GtkBuilders for them. It is very easy to create a single widget from withing the code.

I assume you use Python, since you've tagged your question as pygtk.

Have a look at a simple example:

from gi.repository import Gtk


my_window = Gtk.Window()
my_button = Gtk.Button()

Well, it won't really work on it's own, but that's how you can create new widgets. For details on particular widgets, head to this elegant tutorial/docs:

share|improve this answer
Thanks rafalcieslak. Yes, I am using Python. I am loading data from an internet api and displaying the data in widgets. Thus I need to generate the widgets at runtime. I would like to use Glade as it makes positioning and setting attributes of widgets easy; but why is this use "wrong"? – user72943 Jul 2 '12 at 1:11
@user72943: While glade is meant to make designing easy, it's good only for static interfaces, where nothing changes at runtime. This is because GtkBuilder (as you have noticed) will not work efficiently, if you will ask it to process a .ui file each time you need a new widget... Glade may be helpful here to test widgets layout and work on design - yet it you want your application to work efficiently (especially if you need to do many GUI changes at runtime), you will have to create widgets the "classic way". Luckily. it's very simple and you shouldn't have trouble with it. – Rafał Cieślak Jul 2 '12 at 11:25

If you want different chunks shoved in different areas at run-time, you can build one glade file with loads of windows and re-parent them. For an example check what I did for this other question.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.