在 Ubuntu 11.04 上加载 pygtk 时出现问题

发布于 2024-11-23 17:08:07 字数 1511 浏览 2 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪菊怪哟 2024-11-30 17:08:07

文件中的第三行应为:

pygtk.require('2.0')

因为在本例中 2.0 是字符串,而不是浮点数。

The 3rd line in your file should read:

pygtk.require('2.0')

Because 2.0 is a string in this case, not a float.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文