How to get filename from FileChooserButton in PyGTK?

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.FileChooserAction.OPEN, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) self.add_vfilters(dialog) dialog.set_current_folder('/home') 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' dialog.destroy()

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?

2

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like