Question

dialog = gtk.FileChooserDialog("Open..",
                           None,
                           gtk.FILE_CHOOSER_ACTION_OPEN,
                           (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
                            gtk.STOCK_OPEN, gtk.RESPONSE_OK))
dialog.set_default_response(gtk.RESPONSE_OK)

I want to use the above code for file browsing- but when I give the following import

import pygtk
pygtk.require('2.0')

import gtk

I get Error: No module named 'pygtk'

Do I need to give pygtk as a module inside my application folder? Do say with steps. Thank you.

Was it helpful?

Solution

pygtk is the old and deprecated gtk Python api. Do not use it unless you have a legacy application. The correct way nowadays is to use GObject-introspection to use Gtk3 from Python. Which is also really awesome as it makes Python a first-class supported language, with no wrappers necessary.

from gi.repository import Gtk
dlg = Gtk.FileChooserDialog()
dlg.show()

OTHER TIPS

You should look at this: http://rox.sourceforge.net/desktop/node/245.html

It shows some problems. Good luck on fixing it :).

Edit:

Test PyGTK Installation

This has lots of info on pip install (windows): How do I install pip on Windows?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top