IPyFileChooser

0.6.0 ยท active ยท verified Thu Apr 16

IPyFileChooser is a Python file chooser widget designed for use in Jupyter/IPython notebooks, integrating with `ipywidgets`. It allows users to interactively select file paths and filenames. The library is actively maintained, with its latest stable version 0.6.0 released in September 2021.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize and display the `FileChooser` widget in a Jupyter environment. It sets a default path, applies a file filter, and shows how to access the selected file properties. An example of registering a callback function for dynamic responses to user selections is also included.

import os
from ipyfilechooser import FileChooser
from IPython.display import display

# Get the current working directory as the default path
current_dir = os.getcwd()

# Create and display a FileChooser widget
# You can specify a default path, filename, and filter patterns
fc = FileChooser(current_dir, title='Choose a file:')
fc.filter_pattern = ['*.txt', '*.csv'] # Example: filter for text and CSV files
display(fc)

# To access the selected path and filename after user interaction
# For example, after a button click or callback
# print(f"Selected Path: {fc.selected_path}")
# print(f"Selected Filename: {fc.selected_filename}")
# print(f"Full Selected File: {fc.selected}")

# Example of using a callback function
def on_selection_change(chooser):
    print(f"Callback triggered! Selected: {chooser.selected}")

fc.register_callback(on_selection_change)

view raw JSON โ†’