Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have been using gtk a lot to make my python programs have a graphical interface, and it's pretty awesome. I recently discovered Glade which is a hassle-free way of making a GUI for your programs. I used glade to make the program the way i wanted it to look, and now I would like to look at it's code, but I have no idea how to. Some help would be appreciated, thanks Ubuntu :)

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

It is possible to build GUI dynamically from Glade file using PyGTK Gtk.Builder class

The Gtk.Builder class offers you the opportunity to design user interfaces without writing a single line of code. This is possible through describing the interface by a XML file and then loading the XML description at runtime and create the objects automatically, which the Builder class does for you. For the purpose of not needing to write the XML manually the Glade application lets you create the user interface in a WYSIWYG (what you see is what you get) manner

See this is a nice tutorial: Python GTK+ 3 Tutorial: 20. Glade and Gtk.Builder

Example:

from gi.repository import Gtk

class Handler:
    def onDeleteWindow(self, *args):
        Gtk.main_quit(*args)

    def onButtonPressed(self, button):
        print("Hello World!")

builder = Gtk.Builder()
builder.add_from_file("builder_example.glade")
builder.connect_signals(Handler())

window = builder.get_object("window1")
window.show_all()

Gtk.main()
share|improve this answer
add comment

Your Answer

 
discard

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.