だから、私は pygtk appindicator を作成しており、特定の関数を定期的に呼び出す必要があります。gobject.timeout_add(millisec,function) は、これに対する 1 つの解決策です。
この方法ですべての 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 に置き換えても、同じエラーが発生します。
だから、同じことを解決するのを手伝ってください。前もって感謝します!!