-   Programming (
-   -   Getting GTK to work with python (

crazyjimbo 11-25-2006 08:04 AM

Getting GTK to work with python
Hi all,

I've been trying to learn how to use GTK in Python, but haven't managed to get past the 'Hello World' Example yet. Using the code below, I get the error:

'AttributeError: 'module' object has no attribute 'Window''


#!/usr/bin/env python

# example

import pygtk
import gtk

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

    def main(self):

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

I'm pretty sure I've got all the libraries I need installed (python-gtk2, all the gtk development libraries (I've coded in C with no problem), etc). I'm really stumped as to what is causing this error.

I'm using Debian Etch for the record.

Many Thanks,

ghostdog74 11-25-2006 09:50 AM

How about this?


#!/usr/bin/env python
 import gtk
 class Base:
    def __init__(self):
        self.window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
 def main():
 if __name__ == "__main__":
    base = Base()

Andrew Benton 11-25-2006 10:10 AM

crazyjimbo, your code works for me without error, it opens a little window. It would seem you need to install a python package. This is the list of python packages I have installed, perhaps you need to install one of them?

crazyjimbo 11-27-2006 12:35 PM

ghostdog74: I have tried your code and I get the same error (except it complains about GtkWindow instead of Window).

Andrew Benton: The code SHOULD work, I lifted it straight form the pygtk tutorial, but for some reason it doesn't work for me. As I said, I'm pretty sure I have all the required packages. Although, where you have pygtk, I have a package that apt (I'm in Debian Etch) calls 'python-gtk2'. I had assumed this was the same thing, as it comes up when I search for pygtk.

At this stage, I have no idea what is going on and don't know where to turn to find an answer which is most frustrating!

Many thanks,


crazyjimbo 11-27-2006 01:14 PM

I've installed pygtk from source from the pygtk website and everything works now. I don't whether I didn't actually have pygtk or if the Debian version just wasn't working. Anyway, problem solved, thanks for the help!

All times are GMT -5. The time now is 07:58 AM.