Search code examples
gtkpygobjectgobjectappindicator

gobject name error even though there is no import error


So,I am making a pygtk appindicator and requires a certain function to be called regularly. gobject.timeout_add(millisec,function) is one solution to this.

I have imported all gi modules in this way:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GObject
gi.require_version('Notify', '0.7')
gi.require_version('AppIndicator3', '0.1')

from gi.repository import Gtk as gtk
from gi.repository import AppIndicator3 as appindicator
from gi.repository import Notify as notify

and there has been no import error whatsoever. Then, in my main function I call :

gobject.timeout_add(2000,pr) 

This is the actual code snippet:

def main():
    indicator = appindicator.Indicator.new(APPINDICATOR_ID, os.path.abspath('spotify.svg'),   appindicator.IndicatorCategory.SYSTEM_SERVICES)
    indicator.set_status(appindicator.IndicatorStatus.ACTIVE)
    indicator.set_menu(build_menu())
    notify.init(APPINDICATOR_ID)
    gobject.timeout_add(2000,pr) 
    gtk.main()

and get the following error:

Traceback (most recent call last):
  File "appin.py", line 128, in <module>
    gobject.timeout_add(2000,pr) 
NameError: name 'gobject' is not defined

Even if I replace gobject with GObject I get the same error.

So,please help me to resolve the same. Thank You in advance!!


Solution

  • You forgot the as gobject in your import statement. You remembered it for the other libraries at least. Remember that Python is case-sensitive; GObject and gobject are different.