0

I am new to python and am trying to run a simple program I found on the web. I have installed the pyGTK All In One Download and cannot (after searching on the web for a month or so) find gtk.py anywhere.

It does not exist on my computer no matter how many times i run pygtk-all-in-one-2.24.2.win32-py2.7.msi Here is my code

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

class Simple:

    def destroy(self, widget, data=None):
        gtk.main_quit()

    def __init__(self):
        win = gtk.Window(gtk.WINDOW_TOPLEVEL)

        win.connect("destroy", self.destroy)

        win.set_title("Simple")
        win.set_position(gtk.WIN_POS_CENTER)
        win.show_all()

        Simple()
        gtk.main()

I searched this forum and many others as well. If you have this file, could you post the code so I can copy it? If someone can help I would be very grateful. Thank You for listening. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It seems that I have found the answer from the following link at http://www.slideshare.net/BaabtraMentoringPartner/importerror-dll-load-failed-is-not-a-valid-win32-application-python-mysql. I uninstalled the 64 bit version and installed the 32 bit version. When I run it from the command line the little window comes up! The error still shows up in Netbeans though so maybe the problem is in the Netbeans IDE?

2
  • 1
    What error do you get? Commented Jan 10, 2014 at 17:24
  • I'm getting the error: ImportError: No module named gtk Commented Jan 13, 2014 at 18:22

4 Answers 4

2

The gtk code is in

C:\Python27\Lib\site-packages\gtk-2.0

There is no single file named gtk.py. (There is a _gtk.pyd, which is like a dll).

However, you should generally not need to access the source code for the libraries you install. Python will handle that for you when you import gtk, then you can just use those features within your script.

Sign up to request clarification or add additional context in comments.

Comments

0

If you have another gtk app (like GIMP) you may have problem with enviroment. Also, I hope that the indentation is broken only here, not in your script. And tell us what is the error.

4 Comments

Hello The error I'm getting is Traceback (most recent call last): File "C:\pythonscripts\hello.py", line 20, in <module> import gtk ImportError: No module named gtk
And Yes I do have GIMP installed.Is that a problem?
Yes, the gtk env vars may be set/point to gimp's gtk. Best is to check paths in your enviroments. I don't have a win, but I remember having big problems with gtk when an other app put the path in env vars. I use to manualy set the path to the working libraries, but a windows user may help you with the right path, I don't remember exactly the details
Thank You for your reply. I checked my env/vars and don't see it containing the path to Gimp. So I don't think that's the problem.
0

I guess that using python(64bit ) for Windows 7 was the main problem. So I uninstalled the 64 bit version and installed the 32 bit version and it seems to work fine now. Thanks to everyone for your help. I would like to mark this question as answered but I don't exactly know how.

Comments

0

Uninstall your all-in-one and try with this other all-in-one:

https://sourceforge.net/projects/pygobjectwin32/files/

Then:

import gi   
gi.require_version('Gtk', '2.0')    
from gi.repository import Gtk

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.