AttributeError: 'Style' object has no attribute 'fg_gc'

1k views Asked by At

i'm working on a Gtk.DrawingArea because i want simply draw a rectangle. I've cut and pasted the example of DrawingArea from Gtk examples, cutting off useless code for my purpose.

Here below the code (don't care about indentation problems, it's all ok, Geany IDE sucks):

#!/usr/bin/env python
# -*- coding: utf-8; -*-
from gi.repository import Gtk
import pygtk
pygtk.require('2.0')



class collega_GUI:



    def __init__(self):

            self.__builder = Gtk.Builder()
            self.__builder.add_from_file('prova.glade')

            self.__area = self.__builder.get_object('drawingarea1')

            self.__style = self.__area.get_style()
            self.__gc = self.__style.fg_gc[gtk.STATE_NORMAL]
            self.__pangolayout = self.__area.create_pango_layout("")
            self.__area.draw_rectangle(self.__gc, True, 0, 0, 20, 20)

            self.__pangolayout.set_text("1")
            self.__area.draw_layout(self.gc, 0, 50, self.__pangolayout)

            self.__window = self.__builder.get_object('window1')
            self.__window.show()


if __name__=='__main__':
    prova = collega_GUI()
    Gtk.main()

So the python interpreter says me:

AttributeError: 'Style' object has no attribute 'fg_gc'

Please help me, i've read the documentation at (http://www.pygtk.org/pygtk2tutorial/sec-DrawingAreaWidgetAndDrawing.html) but i can't find the error

1

There are 1 answers

1
drahnr On BEST ANSWER

I think your imports should look like this:

import pygtk
pygtk.require('2.0')
import gtk

You are mixing the pygtk wrapper and the gi.introspection bindings which are two different things! And potentially even mixing gtk2 with gtk3 widgets!


Also keep in mind: that tutorial's last update was in 2005!