'How to show the image after using 'FileUpload' widgets

I am new to Python and I want to show the image after using FileUpload widgets in Python. Also, I want to print the file name.

uploader = widgets.FileUpload()
display(uploader)


Solution 1:[1]

def show_image(file_name):
    img = mpimg.imread("./upload_img/" + file_name)
    plt.imshow(img)
    
def on_button_clicked(b, file_name):
    show_image(file_name)


button = widgets.Button(
    description='Show image',
    disabled=False,
    button_style='info', # 'success', 'info', 'warning', 'danger' or ''
    tooltip='Click me',
    icon='image' # (FontAwesome names without the `fa-` prefix)
)

button.on_click(functools.partial(on_button_clicked, file_name=list(uploader.value.keys())[0]))
display(button)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lumberspin