0

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()

2 Answers 2

5

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()

Sign up to request clarification or add additional context in comments.

Comments

0

Was also getting the required gtk+ version 3x, current version is 2x error

The problem is that the newest version of Glade doesn't run with the default GTK version in Ubuntu.

I finally got it working by installing the older Glade V3.8.5 Note: I'm working on Xenial/16.04.

By installing the older version you can create Glade GUIs that run under GTK2.

Steps:

  • remove the newer Glade (i.e. apt-get remove Glade) version
  • download the V3.8.5 version of Glade (which is the last version to support GTK2) from: http://ftp.gnome.org/pub/GNOME/sources/glade/3.8/
  • follow the install instructions (./configure, make, makeinstall)

I also needed to install these missing components (YMMV):

libgtk2.0-dev, intltool, libxml2-devel

It installed. But... when I ran it.. it died:

glade-3: error while loading shared libraries: libgladeui-1.so.11: cannot open shared object file: No such file or directory

So finally I installed: libgladeui*

Rebooted... voila. Glade runs... the GUI I created works in Python2 (import gtk).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.