I'm using Glade and PyGtk to develop an application. Currently I'm using a button under a toolbar to open files using this code:

    def on_openVideo_clicked(self, widget):
        dialog = Gtk.FileChooserDialog("Please choose a video", self,
            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
             Gtk.STOCK_OPEN, Gtk.ResponseType.OK))

        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            self.videoInput = dialog.get_preview_filename()
            print "Video file Choosen: ", self.videoInput
        elif response == Gtk.ResponseType.CANCEL:
            print 'Cancel Clicked'           


But I decided to replace it with a FileChooserButton because it has better visualization. But I don't know how to print the file name. I guessed it should be something like this:

def on_filechooserbutton_file_set(self, widget):
        print widget.get_filename()

But this doesn't work. So my question is how to retrieve filename from filechooserbutton?

  • I think this question best fits on Stack Overflow. – muru Sep 20 '14 at 8:41
  • I actually post same question, but there was no answer. By the way I found the solution and trying to post it as an answer now. – AliGH Sep 20 '14 at 8:57

This piece of code solved the problem and prints the filename as I wished:

def on_filechooserbutton_file_set(self, widget):
        self.videoInput = widget.get_filename()
        print "Video file Choosen: ", self.videoInput
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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