Help with Python GTK.

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

  1. natatos macrumors regular

    Joined:
    Dec 23, 2008
    Location:
    Iowa
    #1
    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
    Code:
    #!/usr/bin/env Python
    
    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()
            
    if __name__ == "__main__":
        base = Base()
        base.main()
    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

    KnightWRX

    Joined:
    Jan 28, 2009
    Location:
    Quebec, Canada
    #2
    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 :

    http://faq.pygtk.org/index.py?req=show&file=faq01.019.htp

    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 :

    http://developer.apple.com/cocoa/pyobjc.html

    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