Search code examples
pythongtkpygtkgtk2

GTK and PYGTK difference


many programmers import both gtk and pygtk in this way:

import gtk
import pygtk

I have created a simple program using only gtk and it works:

import gtk

window = gtk.Window()
window.set_size_request(800, 700)
window.set_position(gtk.WIN_POS_CENTER)
window.connect("destroy", gtk.main_quit)

button = gtk.Button("Vai")
button.set_size_request(30, 35)
button.connect("clicked", naviga)
testo = gtk.Entry()

h = gtk.HBox()
h.pack_start(testo)
h.pack_start(button)

window.add(h)
window.show_all()
gtk.main()

So... the question is: what is the difference from GTK and PYGTK ?


Solution

  • pygtk is provided by python-gobject. gtk is provided by python-gtk2.

    pygtk provides the pygtk.require function which allows you to require that a certain version of gtk (or better) is installed. For example

    import pygtk
    pygtk.require('2.0')
    

    importing gtk only is possible, but your program may not work as expected on someone else's machine if their version of gtk is older.