I am creating simple project for data entry, i have successfully created the GUI and excel sheet that has to be in the directory, i am kinda struggling with creating column title and assign text entered by user input in the excel sheet, also struggling with making the program itself create an excel file using pandas lib or other libs.
`from openpyxl import load_workbook
import PySimpleGUI as sg
from datetime import datetime
sg.theme('DarkAmber')
layout = [[sg.Text('First Name'),sg.Push(), sg.Input(key='FIRST_NAME')],
[sg.Text('Last Name'),sg.Push(), sg.Input(key='LAST_NAME')],
[sg.Text('TEL:'),sg.Push(), sg.Input(key='NUMBER')],
[sg.Text('File name:'), sg.Input(key='File_name')] #user use this file name to create new file
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
sg.InputText('Default Folder'), sg.FolderBrowse()], #failed to make it create an excel file to create new directory
[sg.Button('Submit'), sg.Button('Close')]]
window = sg.Window('Data Entry', layout, element_justification='center')
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Close':
break
if event == 'Submit':
try:
wb = load_workbook('Book1.xlsx')
sheet = wb['Sheet1']
ID = len(sheet['ID']) + 1
time_stamp = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
data = [ID, values['FIRST_NAME'], values['LAST_NAME'], values['NUMBER'], time_stamp]
sheet.append(data)
wb.save('Book1.xlsx')
window['FIRST_NAME'].update(value='')
window['LAST_NAME'].update(value='')
window['NUMBER'].update(value='')
window['FIRST_NAME'].set_focus()
sg.popup('Success', 'Data Saved')
except PermissionError:
sg.popup('File in use', 'File is being used by another User.\nPlease try again later.')
window.close()`
I have tried using Pandas lib for creating excel file but failed to make it recognized by the GUI and to add to the GUI a place to create or save as commented next to the Default folder.
I have faced problems with :
- using the PySimpleGUI to create titles with text and take its input in the excel sheet for example if user entered first name, the title in the excel sheet should automatically named as First name :)
- use the a function instead of (sg.FolderBrowse()) to create new file or open existing file,I couldnt find in the cookbook of the PySimpleGUI.