ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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!
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.