Python GTK“入门”教程问题

发布于 2024-10-09 15:53:03 字数 1010 浏览 0 评论 0原文

我在编译 pygtk 网站上列出的基本且非常简单的 PyGTK 使用示例时遇到问题。

这是该网站的第一个示例: http://www.pygtk.org/pygtk2tutorial/ch-GettingStarted.html

我的代码如下所示:

#!/usr/bin/env python

# example gtk.py

import pygtk
pygtk.require('2.0')
import gtk

class Base:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.show()

    def main(self):
        gtk.main()

print __name__
if __name__ == "__main__":
    base = Base()
    base.main()

在调用 python gtk.py 后,我收到以下错误:

GTK 主要 回溯(最近一次调用最后一次): 文件“gtk.py”,第 19 行,位于 基数 = 基数() 文件“gtk.py”,第 11 行,位于 init 中 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) AttributeError:“模块”对象没有属性“窗口”

我在某处找到了一个信息,它应该通过从源代码安装 PyGTK 来修复。我做到了,但没有改变什么。消息还是一样。

我正在使用 ubuntu 10.10

您对可能出现的问题有什么想法吗? 感谢您的帮助!

麦克风

I have a problem with compiling a basic and really simple example of PyGTK usage listed on pygtk's website.

This is the first example from this site:
http://www.pygtk.org/pygtk2tutorial/ch-GettingStarted.html

My code looks like this:

#!/usr/bin/env python

# example gtk.py

import pygtk
pygtk.require('2.0')
import gtk

class Base:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.show()

    def main(self):
        gtk.main()

print __name__
if __name__ == "__main__":
    base = Base()
    base.main()

And after calling python gtk.py, i'm getting the following error:

gtk
main
Traceback (most recent call last):
File "gtk.py", line 19, in
base = Base()
File "gtk.py", line 11, in init
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
AttributeError: 'module' object has no attribute 'Window'

I've found an info somewhere that it shpuld be fixed by installing PyGTK from source. I did it but it changed nothing. The message is still the same.

I'm using ubuntu 10.10

Have you any ideas on what can be wrong ?
Thanks for any help!

Mike

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦明 2024-10-16 15:53:03

是的,看来您可能已将脚本命名为“gtk.py”。

这是一个坏主意,原因应该是相当明显的!

Yep, it seems like you might have named your script "gtk.py".

Which is a bad idea for what should be fairly obvious reasons!

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