Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python GTK "Getting started" tutorial problem

Tags:

python

pygtk

gtk

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

like image 436
mbajur Avatar asked Feb 25 '23 12:02

mbajur


1 Answers

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

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

like image 80
William Avatar answered Mar 08 '23 10:03

William