2017-01-09 34 views
0

所以,我正在製作一個pygtk appindicator,並且需要定期調用某個函數。 gobject.timeout_add(millisec,function)是解決這個問題的方法之一。儘管沒有導入錯誤,gobject名稱錯誤

我已經導入了所有GI模塊以這樣的方式

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 

,至今沒有任何導入錯誤。 然後,在我的主要功能我打電話:

gobject.timeout_add(2000,pr) 

這是實際的代碼片段:

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() 

,並出現以下錯誤:

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

即使我更換的GObject與GObject我得到同樣的錯誤。

所以,請幫我解決同樣的問題。 提前謝謝你!

回答

3

您在導入聲明中忘記了as gobject。至少你還記得其他的圖書館。請記住,Python是區分大小寫的; GObjectgobject是不同的。

+0

非常感謝! – sjboss

相關問題