Skip to content

Commit c13c8fe

Browse files
committed
Create A Data Entry Form Using Python PySimpleGUI
Create A Data Entry Form Using Python PySimpleGUI
1 parent 12f069e commit c13c8fe

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

Data.xlsx

6.45 KB
Binary file not shown.

main.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import PySimpleGUI as sg
2+
import pandas as pd
3+
4+
# Add some color to the window
5+
sg.theme('DarkTeal9')
6+
7+
EXCEL_FILE = 'Data.xlsx'
8+
df = pd.read_excel(EXCEL_FILE)
9+
10+
layout = [
11+
[sg.Text('Please fill out the following fields:')],
12+
[sg.Text('Name', size=(15,1)), sg.InputText(key='Name')],
13+
[sg.Text('City', size=(15,1)), sg.InputText(key='City')],
14+
[sg.Text('Favorite Colour', size=(15,1)),
15+
sg.Combo(['Green', 'Blue', 'Red'], key='Favorite Colour')],
16+
[sg.Text('I speak', size=(15,1)),
17+
sg.Checkbox('German', key='German'),
18+
sg.Checkbox('Spanish', key='Spanish'),
19+
sg.Checkbox('English', key='English')],
20+
[sg.Text('No. of Children', size=(15,1)), sg.Spin([i for i in range(0,16)],
21+
initial_value=0, key='Children')],
22+
[sg.Submit(), sg.Button('Clear'), sg.Exit()]
23+
]
24+
25+
window = sg.Window('Simple data entry form', layout)
26+
27+
def clear_input():
28+
for key in values:
29+
window[key]('')
30+
return None
31+
32+
33+
while True:
34+
event, values = window.read()
35+
if event == sg.WIN_CLOSED or event == 'Exit':
36+
break
37+
if event == 'Clear':
38+
clear_input()
39+
if event == 'Submit':
40+
new_record = pd.DataFrame(values, index=[0])
41+
df = pd.concat([df, new_record], ignore_index=True)
42+
df.to_excel(EXCEL_FILE, index=False)
43+
sg.popup('Data saved!')
44+
clear_input()
45+
window.close()

0 commit comments

Comments
 (0)