在 Ubuntu 11.04 上加载 pygtk 时出现问题
我正在尝试在 Python 中使用 pygtk,但是当我尝试运行我的代码时,出现此错误:
Traceback (most recent call last):
File "application.py", line 3, in <module>
pygtk.require(2.0)
File "/usr/lib/python2.7/dist-packages/pygtk.py", line 85, in require
"required version '%s' not found on system" % version
AssertionError: required version '2.0' not found on system
这是我尝试运行的代码(它基本上是 pygtk 网站上的 Hello World 示例):
#!/usr/bin/env python
import pygtk
pygtk.require(2.0)
import gtk
class Application():
def hello(self, widget, data=None):
print 'Hello World'
def delete_event(self, widget, event, data=None):
print 'delete even occurred'
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect('delete_event', self.delete_event)
self.quitButton = Button(self, text='Quit', command=self.quit)
self.quitButton.grid()
self.window.set_border_width(10)
self.button = gtk.Button('Hello World')
self.button.connect('clicked', self.hello, None)
self.button.connect_object('clicked', gtk.Widget.destroy, self.window)
self.window.add(self.button)
self.button.show()
def main(self):
gtk.main()
def main():
app = Application()
app.main()
if __name__ == '__main__':
main()
另外,当我尝试运行时pygtk-demo 一切正常,即使它以与我相同的方式导入库。它还输出 PyGTK Demo (gtk: v2.24.4, pygtk: v2.22.0)
所以你可以看到我有一个 >2.0 的版本。
I'm trying to use pygtk in Python but when I try running my code I get this error:
Traceback (most recent call last):
File "application.py", line 3, in <module>
pygtk.require(2.0)
File "/usr/lib/python2.7/dist-packages/pygtk.py", line 85, in require
"required version '%s' not found on system" % version
AssertionError: required version '2.0' not found on system
Here is the code I'm trying to run (it's basically the Hello World example from the pygtk website):
#!/usr/bin/env python
import pygtk
pygtk.require(2.0)
import gtk
class Application():
def hello(self, widget, data=None):
print 'Hello World'
def delete_event(self, widget, event, data=None):
print 'delete even occurred'
return False
def destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect('delete_event', self.delete_event)
self.quitButton = Button(self, text='Quit', command=self.quit)
self.quitButton.grid()
self.window.set_border_width(10)
self.button = gtk.Button('Hello World')
self.button.connect('clicked', self.hello, None)
self.button.connect_object('clicked', gtk.Widget.destroy, self.window)
self.window.add(self.button)
self.button.show()
def main(self):
gtk.main()
def main():
app = Application()
app.main()
if __name__ == '__main__':
main()
Also, when I try running pygtk-demo
everything works ok, even though it is importing the library the same way that I am. Also it outputs PyGTK Demo (gtk: v2.24.4, pygtk: v2.22.0)
so you can see that I have a version that is >2.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
文件中的第三行应为:
因为在本例中
2.0
是字符串,而不是浮点数。The 3rd line in your file should read:
Because
2.0
is a string in this case, not a float.