Experimental Faster Version of PySimpleGUI 2020 Part 7 – Button Targets (File & Other Choosers)

Posted by


In this tutorial, we will explore the new Button Targets feature in PySimpleGUI 2020, specifically focusing on file and other choosers. This feature allows for faster file selection and other chooser options to enhance user experience. Please note that this feature is still experimental and may need further testing before using it in production.

First, make sure you have PySimpleGUI 2020 installed on your Python environment. You can install it using pip:

pip install PySimpleGUI==4.37.0

Now, let’s get started with the implementation of Button Targets for file and other choosers:

import PySimpleGUI as sg

# Define the layout of the GUI
layout = [
    [sg.Text('Select a file:')],
    [sg.Input(key='file_path'), sg.FileBrowse(target='file_path')],
    [sg.Button('Select Folder', button_color=('white', 'black'), target='folder_path'),
     sg.Input(key='folder_path'), sg.FolderBrowse()],
    [sg.Button('Select Font', button_color=('white', 'black'), target='font_path'),
     sg.Input(key='font_path'), sg.FontChooser()],
    [sg.Button('Submit')]
]

# Create the window
window = sg.Window('Button Targets Tutorial', layout)

# Event loop
while True:
    event, values = window.read()

    if event == sg.WIN_CLOSED or event == 'Submit':
        break

# Close the window
window.close()

In this code snippet, we have created a simple GUI with input fields for file paths, folder paths, and font selection. We have added Button Targets to the file browse, folder browse, and font chooser buttons, allowing for faster selection of these options.

By setting the target parameter in the FileBrowse, FolderBrowse, and FontChooser elements, we can link the buttons to the input fields where the selected paths or fonts will be displayed. This feature enhances the user experience by providing a more intuitive way to select files and other options.

Please note that the Button Targets feature is still experimental, and there may be some bugs or limitations that need to be addressed. It is recommended to test this feature thoroughly before using it in production applications.

Overall, Button Targets in PySimpleGUI 2020 provide a convenient way to enhance user interaction with file and other choosers in GUI applications. Experiment with this feature and see how it can improve the user experience in your projects.

0 0 votes
Article Rating

Leave a Reply

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@tatololeseditatolo8857
4 days ago

How do I add a time(only) input button as H:m:s?

@jorgegil13283
4 days ago

Simply perfect 🥰

2
0
Would love your thoughts, please comment.x
()
x