Python PySimpleGUI Tutorial: How to Create a Data Entry Form

Posted by


PySimpleGUI is a Python library that makes it easy to create graphical user interfaces (GUIs) for your Python programs. In this tutorial, we will be using PySimpleGUI to create a data entry form where users can input information into various fields and submit the form.

To get started with PySimpleGUI, you will first need to install it using pip. Open your command prompt or terminal and run the following command:

pip install PySimpleGUI

Once you have PySimpleGUI installed, you can start creating your data entry form. Here’s an example of a simple form with fields for entering a name, email, and phone number:

import PySimpleGUI as sg

layout = [
    [sg.Text('Name:'), sg.InputText(key='name')],
    [sg.Text('Email:'), sg.InputText(key='email')],
    [sg.Text('Phone Number:'), sg.InputText(key='phone')],
    [sg.Button('Submit')]
]

window = sg.Window('Data Entry Form', layout)

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

    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'Submit':
        name = values['name']
        email = values['email']
        phone = values['phone']

        print(f'Name: {name}, Email: {email}, Phone Number: {phone}')

window.close()

In this code snippet, we first import the PySimpleGUI library. Next, we define the layout of our form using a list of lists, where each inner list represents a row of the form. Each row contains a text label and an input field using the sg.Text and sg.InputText functions, respectively.

We also add a Submit button to allow users to submit the form data. When the Submit button is clicked, the while loop reads the form values and prints them to the console.

To run the form, simply save the code to a Python file and execute it using a Python interpreter. You should see a window pop up containing the data entry form. You can enter values into the fields and click the Submit button to see the entered data printed to the console.

This is just a basic example of a data entry form using PySimpleGUI. You can customize the form by adding more fields, changing the layout, and modifying the logic to suit your specific needs. PySimpleGUI offers a wide range of input elements, layout options, and event handling features to help you create complex and interactive GUIs for your Python programs.

0 0 votes
Article Rating

Leave a Reply

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@CommandCell464
3 days ago

How do you have a separate window with your code results

@southvillechris
3 days ago

This is a really excellent and useful video, showing everything step by step. Thank you!

@azizchowdhury7666
3 days ago

Help!
can i update the existing data or overwrite every time instead of appending one after another .if anyone know this please help.

@amandanoronha2893
3 days ago

This is a nice video, but I have some problems :(, for some reason give me the message 'ValueError: Excel file format cannot be determined, you must specify an engine manually.' could you help me?

@Faneshnsh
3 days ago

I am really grateful for the videos u are making because if I want to learn how to make these projects I would need to take alot of courses and pay alot of money but u make these projects on YouTube for free also u save me so much time 😊😁

@turtlecode
3 days ago

👉 Don't forget to check out other playlists.

https://www.youtube.com/@turtlecode/playlists

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