5

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

Vance T
  • 175

2 Answers2

2

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

and:

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

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: http://python-gtk-3-tutorial.readthedocs.org/

2

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.

RobotHumans
  • 30,112