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