Question

i've to use GtkGrid because i need to draw a rectangle for every item i have. (i would add a Drawing area to every GtkGrid's cell and draw the rectangle by cairographics library)

But there was a problem: python 2.7 doesn't support GtkGrid, so i surfed the web and i simply changed the first line of my file (and installed python3.3).

#!/usr/bin/python3.3

try:  
    import pygtk  
    pygtk.require("2.0")  
except:  
    print("PyGtk Not Availible")
    sys.exit(1)

try:  
    import gtk  
    import gtk.glade  
except:  
    print("GTK Not Availible")
    sys.exit(1)

Now it cannot rescue anymore Pygtk or GTK libraries.. and with python2.7 all work fine.. Maybe the best solution would be to avoid newer python interpreters and change GtkGrid into something else..

Help me please

EDIT:: Just cut and pasted an example from Pygtk examples

#!/usr/bin/python3.3

# example drawingarea.py

import pygtk
pygtk.require('2.0')
import gtk
import operator
import time
import string

class DrawingAreaExample:
    def __init__(self):
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        window.set_title("Drawing Area Example")
        window.connect("destroy", lambda w: gtk.main_quit())
        self.area = gtk.DrawingArea()
        self.area.set_size_request(400, 300)
        self.pangolayout = self.area.create_pango_layout("")
        self.sw = gtk.ScrolledWindow()
        ...

With Python 2.7 it works, with Python 3.3: No module named 'pygtk'

Was it helpful?

Solution

Just to make this clear: You have to decide wether you want to use the gi.introspection bindings (which are up to date and mostly autogenerated) or the pygtk wrapper around gtk+-2.0 (hand crafted, as of now pygtk3 is still work in progress, correct me if I am wrong).

Mixing these will get you in trouble further or later.


Also your initial issue was, GtkGrid (part of gtk+-3.0) was part of the gi.introspection bindings which (usually) require Python 3.x.y, whereas you used pygtk2 with Python 2.7.x. Changing to Python 3.3 just made the bindings availiable to you.


In gtk2 GtkGrid was called GtkTable, see https://developer.gnome.org/gtk2/stable/GtkTable.html.

OTHER TIPS

Try this:

#!/usr/bin/env python
# -*- coding: utf-8; -*-
from gi.repository import Gtk
grid = Gtk.Grid()

You need to use GTK+ 3, not python3.3 (in order to have a Gtk.Grid)... if i understand what you mean...

Edited.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top