FileChooserButton

The FileChooserButton provides access to a FileChooserDialog. The button is used when space is limited to allow selecting of a file.

Constructor

The FileChooserButton can be constructed using the following:

filechooserbutton = Gtk.FileChooserButton(action)

The action parameter should be set to either Gtk.FileChooserAction.OPEN which allows opening of files, Gtk.FileChooserAction.SAVE which allows files to be saved, Gtk.FileChooserAction.SELECT_FOLDER which enables selecting of folders and Gtk.FileChooserAction.CREATE_FOLDER which creates folders based on a specified name.

Methods

To specify a title on the dialog that appears, use the method:

filechooserbutton.set_title(title)

Signals

The signals used by the FileChooserButton are:

"file-set" (filechooserbutton)

When the user picks a file, the "file-set" signal emits.

Example

Below is an example of a FileChooserButton:

#!/usr/bin/env python3

from gi.repository import Gtk

def file_changed(filechooserbutton):
    print("File selected: %s" % filechooserbutton.get_filename())

window = Gtk.Window()
window.set_default_size(150, -1)
window.connect("destroy", Gtk.main_quit)

filechooserbutton = Gtk.FileChooserButton(title="FileChooserButton")
filechooserbutton.connect("file-set", file_changed)
window.add(filechooserbutton)

window.show_all()

Gtk.main()

Download: FileChooserButton