Matthias Loibl
Matthias Loibl

Reputation: 883

Gtk object has no attribute 'ICON_SIZE_BUTTON'

I'm nearly new to python and new to gtk.

I just can't figure out, why I get this error message:

self.builder.get_object("checkstatus").set_from_stock("gtk-yes", Gtk.ICON_SIZE_BUTTON)
.......
AttributeError: 'gi.repository.Gtk' object has no attribute 'ICON_SIZE_BUTTON'

At the beginning I'm importing:

import pygtk
pygtk.require('2.0')
from gi.repository import Gtk

So the problem is that gtk has no no attribute called 'ICON_SIZE_BUTTON'? But when I look at the documentation it says so...

http://developer.gnome.org/pygtk/2.22/class-gtkimage.html#method-gtkimage--set-from-stock

I would appreciate any help. Thanks!

Upvotes: 3

Views: 2369

Answers (1)

Micah Carrick
Micah Carrick

Reputation: 10197

Well, there's a few things going on.

For GTK+ 3 which uses PyGObject, you use from gi.repository import Gtk and then use Gtk.IconSize.BUTTON.

For GTK+ 2 which uses PyGTK you use import pygtk and import gtk and then use gtk.ICON_SIZE_BUTTON.

In other words, you're mixing up versions. PyGTK (GTK 2) was replaced by PyGObject and something called "gobject introspection" in GTK 3. Check out this tutorial: http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html

Upvotes: 8

Related Questions