Python script using Glade code produces glib error about old version of GTK
Question: I am trying to create my first Glade GUI using Python as the back-end. I
created the GUI in Glade and saved the file as a .glade. I then created my
Python code and saved it in the same directory as the glade file. Upon running
the Python file in the terminal, I receive the following message:

    
    
        Traceback (most recent call last):
          File "glade6.py", line 56, in <module>
            main = Buglump()
          File "glade6.py", line 20, in __init__
            self.builder.add_from_file("glade6.glade")
        glib.GError: glade6.glade: required gtk+ version 3.10, current version is 2.24
    

OS: Ubuntu 14.04.1 LTS 64-bit

And the Python file that was run: Code acquired from
'<http://gnipsel.com/glade/index.html>'

    
    
        #!/usr/bin/env python
        import sys
    
        try: 
          import gtk
          import gtk.glade
        except:
          print('GTK not available')
          sys.exit(1)
        try:
          import pygtk
          pygtk.require('2.0')
        except:
          pass
    
        class Buglump:
    
          def __init__(self):
            self.builder = gtk.Builder()
            self.builder.add_from_file("glade6.glade")
            self.builder.connect_signals(self)
    
            # the liststore
            self.liststore = gtk.ListStore(int,str)
            self.liststore.append([0,"Select an Item:"])
            self.liststore.append([1,"Row 1"])
            self.liststore.append([2,"Row 2"])
            self.liststore.append([3,"Row 3"])
            self.liststore.append([4,"Row 4"])
            self.liststore.append([5,"Row 5"])
    
            # the combobox
            self.combobox = self.builder.get_object("combobox1")
            self.combobox.set_model(self.liststore)
            self.cell = gtk.CellRendererText()
            self.combobox.pack_start(self.cell, True)
            self.combobox.add_attribute(self.cell, 'text', 1)
            self.combobox.set_active(0)
    
            self.window = self.builder.get_object("window1")
            self.window1.show()
    
          def on_combobox1_changed(self, widget, data=None):
            self.index = widget.get_active()
            self.model = widget.get_model()
            self.item = self.model[self.index][1]
            print "ComboBox Active Text is", self.item
            print "ComboBox Active Index is", self.index
            self.builder.get_object("label1").set_text(self.item)
    
          def on_window1_destroy(self, object, data=None):
            print "quit with cancel"
            gtk.main_quit()
    
        if __name__ == "__main__":
          main = Buglump()
          gtk.main()
    


Answer: `import gtk` actually imports `gtk+2.x`. If you need to use `gtk+3`, assuming
you already have it installed, you need to write:

    
    
    From gi.repository import Gtk (with capital letter G)
    

Remove these lines:

    
    
    import gtk
    
    import gtk.glade
    

and remember to change all instances of `gtk` inside your code to `Gtk`.
Example: change `gtk.main_quit()` to `Gtk.main_quit()`

