LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-25-2006, 07:04 AM   #1
crazyjimbo
Member
 
Registered: Mar 2006
Location: Edinburgh
Distribution: Debian Etch, Gentoo
Posts: 90

Rep: Reputation: 16
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''

Code:
#!/usr/bin/env python

# example base.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()
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,
James
 
Old 11-25-2006, 08:50 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
How about this?

Code:
 #!/usr/bin/env python
 import gtk
 class Base:
     def __init__(self):
         self.window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL)
         self.window.show()
 def main():
     gtk.mainloop()
  
 if __name__ == "__main__":
     base = Base()
     main()
 
Old 11-25-2006, 09:10 AM   #3
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
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?
pycairo-1.2.0.tar.gz
pygobject-2.11.1.tar.bz2
pygtk-2.9.0.tar.bz2
pyorbit-2.14.1.tar.bz2
PyPanel-2.4.tar.gz
Python-2.4.3.tar.bz2
python-xlib-0.12.tar.gz
PyXML-0.8.4.tar.gz
 
Old 11-27-2006, 11:35 AM   #4
crazyjimbo
Member
 
Registered: Mar 2006
Location: Edinburgh
Distribution: Debian Etch, Gentoo
Posts: 90

Original Poster
Rep: Reputation: 16
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,

James
 
Old 11-27-2006, 12:14 PM   #5
crazyjimbo
Member
 
Registered: Mar 2006
Location: Edinburgh
Distribution: Debian Etch, Gentoo
Posts: 90

Original Poster
Rep: Reputation: 16
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!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
smart gui - support for gtk python interface rioch Linux - Software 2 06-25-2006 02:43 PM
LXer: How to use GTK+ in C and a C# Python comparison LXer Syndicated Linux News 0 01-12-2006 12:31 PM
python/glade attach window content in gtk.fixed() a10392 Linux - Software 3 10-08-2004 09:19 AM
WineX, python-gnome, and python-gtk DrD Fedora 0 08-03-2004 12:11 PM
installing visual python : gtk present but unfound Dominik Linux - General 0 12-26-2003 10:31 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration