Help with Python GTK.

Discussion in 'Mac Programming' started by natatos, Mar 9, 2011.

  1. natatos macrumors regular

    Dec 23, 2008
    Hi, I'm trying to learn how to program so I'm really new to this and I thought python would be good because it seemed simple and its cross platform, so I was watching a tutorial on YouTube for making a window.
    Heres the code
    #!/usr/bin/env Python
    import pygtk
    import gtk
    class Base:
        def __init__(self):
            self.Window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        def main(self):
    if __name__ == "__main__":
        base = Base()
    When I try to run it it says 'No module named pygtk' I'm used Text Wrangler for it and got that result but if I write it in Terminal I get basically the same thing. So I'm wondering how would I have it find the pygtk, or not need it?
  2. KnightWRX macrumors Pentium


    Jan 28, 2009
    Quebec, Canada
    If you want to write GUI code using GTK (and follow the GTK tutorials), you cannot be without pygtk unfortunately. OS X support for pygtk is either through X11 or through a very early native port that requires building GTK yourself :

    Of course, you probably want PyObjC instead. You'll have to find tutorials on it obviously and can't use the pygtk stuff, but Apple seems to have a good primer here :

    BTW, yes, Python is a good place to start coding. I would however suggest you put aside the GUI stuff for now and concentrate on learning to code. Just use a text mode interface using only the print function.

Share This Page