tags:

views:

49

answers:

1

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 ?

+4  A: 

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.

unutbu
So pygtk is used only to require that a certain version of gtk is installed ?
xRobot
@xRobot: Yes. If you open a Python REPL, and type `import pygtk; pygtk.__file__` you'll find the path to the package. It might be something like `/usr/lib/pymodules/python2.6/pygtk.pyc`. If you take the `c` off the end of the path, and look inside the file `/usr/lib/pymodules/python2.6/pygtk.py` you'll find it defines just three functions, and they all have to do with determining and requiring versions. It is merely by looking at this file that I am surmising/concluding what `pygtk` is for.
unutbu
thanks for useful tips ;)
xRobot