我最近使用 Homebrew 安装了 pygtk 以尝试运行以下程序:
#!/usr/bin/python3
from gi.repository import Gtk, GObject
import time
class TimerWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Timer")
self.timer = Gtk.Label()
self.add(self.timer)
def update(self):
self.timer.set_text(time.strftime('%H:%M:%S'))
return True
if __name__ == "__main__":
win = TimerWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
GObject.timeout_add(200, win.update)
Gtk.main()
该程序在多个 Linux 发行版中运行良好,但在我的 Mac 上运行时遇到了一些麻烦。
似乎python找不到gi
包,这很奇怪,因为我已经安装了它(?)。诚然,我对 python 很陌生,所以我可能弄错了。
运行时给出的错误如下:
File "test.py", line 2, in <module>
from gi.repository import Gtk, GObject
ImportError: No module named gi.repository
我在网上遵循了多个关于如何安装库的指南,但似乎没有一个有效。
有没有人有这方面的经验,或者可以使程序在 OSX 上正常工作?
非常感谢