Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have already added the listeners and etc, but I can't get the actual open dialog code to work. I think it is something to do with the difference between gtk and Gtk but I literally just started python yesterday. Here is my code as of now:

dialog = Gtk.FileChooserDialog("Open..",
                           (Gtk.STOCK_CANCEL, Gtk.RESPONSE_CANCEL,
                            Gtk.STOCK_OPEN, Gtk.RESPONSE_OK))

When the button is pressed, the console output this:

Traceback (most recent call last):
File "/home/nja/notetaker/notetaker/", line 61, in on_btn_open_clicked
File "/home/nja/notetaker/notetaker/", line 41, in open_file
NameError: global name 'GTK_FILE_CHOOSER_ACTION_OPEN' is not defined

Also when GTK_FILE_CHOOSER_ACTION_OPEN is substituted for "0" (Which I believe is the int that constant points to) it works fine but it flags up the same error on Gtk.RESPONSE_CANCEL and Gtk.RESPONSE_OK

share|improve this question
up vote 2 down vote accepted

You must replace:

  • GTK_FILE_CHOOSER_ACTION_OPEN with Gtk.FileChooserAction.OPEN
  • Gtk.RESPONSE_CANCEL with Gtk.ResponseType.CANCEL
  • Gtk.RESPONSE_OK with Gtk.ResponseType.OK


This is not PyGTK, it's GObject Introspection. You must build names as follows: Gtk.EnumTypeNameHere.VALUE


share|improve this answer
Thank you. This worked perfectly! – njallam Jun 21 '12 at 13:29
I will vote your answer up as soon as I have the sufficient reputation :) – njallam Jun 21 '12 at 13:32
done. Thanks again for the help. – njallam Jun 21 '12 at 14:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.