1

I am porting python 2 to python 3. When running application giving below error: AttributeError: 'gi.repository.Gtk' object has no attribute 'gdk'

Any idea to fix this!! Thanks

closed as off-topic by muru, David Foerster, Ravexina, Pilot6, Sumeet Deshmukh May 31 '17 at 14:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – muru, David Foerster, Ravexina, Sumeet Deshmukh
If this question can be reworded to fit the rules in the help center, please edit the question.

2

Well, without your code, I can't be sure, but this is most likely caused by an incorrect import statement. It's possible and highly likely that the import statement for Gdk changed between Python 2 and Python 3.

Try changing the from gi.repository.Gtk import gdk line to from gi.repository import Gdk. That's what I have in some of my code and it works fine. Make sure you get the capitalization correct though, Gdk is different from gdk.

  • I tried both. still same error. Could you please share list of packages needs to be install to work. – mrudula Nov 13 '15 at 19:43
  • How to access gdk api e.g gtk.gdk.color_parser() how to modify for new Gdk? – mrudula Nov 13 '15 at 19:46
  • @mrudula Can you edit your question with the part of your code that is importing the Gtk and Gdk and the entire Traceback? – RPiAwesomeness Nov 13 '15 at 19:47
  • Traceback (most recent call last): File "./vcontrol", line 37, in <module> import app_globals as g File "/home/vilter/vcontrol/lib/python/app_globals.py", line 282, in <module> COLOR_WHITE = gtk.gdk.color_parse('#ffffff') File "/usr/lib/python3/dist-packages/gi/module.py", line 320, in getattr return getattr(self._introspection_module, name) File "/usr/lib/python3/dist-packages/gi/module.py", line 139, in getattr self.__name__, name)) AttributeError: 'gi.repository.Gtk' object has no attribute 'gdk' – mrudula Nov 13 '15 at 20:16
  • Ah. Try changing the code on line 282 in app_globals.py to COLOR_WHITE = gdk.color_parse("#ffffff") – RPiAwesomeness Nov 13 '15 at 20:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.