4

I've made an interface using Glade. I want to then create a subclass of gtk.Window - in Python - and pass in that file to it. Then I'd like to be able to play with the widgets that I added in Glade as I would if I'd created them using regular code.

Here is something I'd quite like to do:

class MainWindow (gtk.Window):
    def __init__(self):
        self.set_creator('gladefile.ui')
        self.get_object('button1').set_label("Hello, World!")

Whilst I've made some things using GTK, I'm not hugely experienced, so cut me some slack please! So, is this possible and if so, any tips? :-)

  • This might help you: http://comments.gmane.org/gmane.comp.gnome.gtk%2B.python/2601 – dumbmatter Aug 21 '11 at 03:41
  • I have actually done this. But it's not well documented and is somewhat involved and lengthy to explain. I'll see if I can write something up later. – Keith Aug 21 '11 at 07:06
  • Thanks for the link Jeremy, much appreciated. Keith, if you'd be able to do that I'd be very grateful. Thanks. –  Aug 21 '11 at 10:56

1 Answers1

0

Try this:

class MainWindow (gtk.Window):
    def __init__(self):
        self.builder = gtk.Builder()
        self.builder.add_from_file('gladefile.ui')
        self.builder.get_object('button1').set_label("Hello, World!")

Gtk.Window and Gtk.Builder are different.