我使用 jhbuild 在我的 Ubuntu 13.10 上成功地(显然!)安装了 gtk+,点击这个链接: http://python-gtk-3-tutorial.readthedocs.org/en/latest/install.html
但是当我运行以下简单程序时:
#!/usr/bin/python
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
我收到这个错误:
Gtk-Message: Failed to load module "overlay-scrollbar"
Gtk-Message: Failed to load module "unity-gtk-module"
Gtk-Message: Failed to load module "canberra-gtk-module"
Traceback (most recent call last):
File "intro.py", line 4, in <module>
win=GtkWindow()
NameError: name 'GtkWindow' is not defined
在四处搜索了一下,我发现了这些类似的问题:
https://askubuntu.com/questions/342202/failed-to-load-module-canberra-gtk-module-but-already-installed https://askubuntu.com/questions/208431/failed-to-load-module-canberra-gtk-module?rq=1
但我仍然得到错误。
还有这些:
Python Gtk+ development in Linux using Eclipse + PyDev, Unresolved import: Gtk PyCharm can not resolve PyGObject 3.0, but code runs fine
不要真的给出解决方案。
我该如何解决这个问题?
更新 1:所以,显然错误是由于代码中的 GtkWindow 而不是 Gtk.Window,但即使在更正它之后,也会显示相同的警告(尽管,现在我没有得到错误并得到正确的输出)
最佳答案
根据你的回溯:
Traceback (most recent call last):
File "intro.py", line 4, in <module>
win=GtkWindow()
NameError: name 'GtkWindow' is not defined
在第 4 行的代码示例中,您有:
win = Gtk.Window()
但错误表明你实际上有:
win=GtkWindow()
您在实际代码中不小心省略了 .
和 Window
之间的 .
但在您发布的示例中修复了它。我建议仔细检查 intro.py 中的那一行,看看是否能解决您的问题。
- 注意:这与未能加载这 3 个模块的警告完全无关。
关于python - Gtk 消息 : Failed to load module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22270826/