From e3385afb4241a1df0509779b175d6fa2a920ef2e Mon Sep 17 00:00:00 2001 From: BrightCove Date: Fri, 24 Jan 2025 23:55:10 -0800 Subject: [PATCH] Upload files to "/" --- python.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 python.py diff --git a/python.py b/python.py new file mode 100644 index 0000000..a6ab32e --- /dev/null +++ b/python.py @@ -0,0 +1,47 @@ +import PySimpleGUI as GUI +import csv +GUI.set_options(font='Arial 15') + +layout = [ + [GUI.Text("First Name"), GUI.Push(), GUI.InputText(key='-fname-')], + [GUI.Text("Last Name"), GUI.Push(), GUI.InputText(key='-lname-')], + [GUI.Text("Phone Number"), GUI.Push(), GUI.InputText(key='-phone-')], + [GUI.Text("Priority Level"), GUI.Push(), GUI.InputText(key='-PrLvl-')], + [GUI.Button("Save")], + [GUI.Text("LegacySearch by Last Name"),GUI.Push(),GUI.InputText(key='-Search-'),GUI.Button('Search')], + [GUI.Text(key='-SearchOutput-')] + ] +window = GUI.Window("Contact Book", layout) +#The While True loop is considered essential +while True: + event, values = window.read() + if event == GUI.WIN_CLOSED: + print("GoodBye!") + break + #If that's not the case + UserFirstName = values['-fname-'] + UserLastName = values['-lname-'] + UserPhoneNumber = values['-phone-'] + Priority = values['-PrLvl-'] + info = [UserFirstName, UserLastName, UserPhoneNumber, Priority] + #If the user wishes to save + if event == "Save": + with open("info.csv", 'a', newline="") as w: + csv.writer(w).writerow(info) + print(info) + #Now that your friend's info is saved locally, + #Clear the fields + window['-fname-'].update('') + window['-lname-'].update('') + window['-phone-'].update('') + window['-PrLvl-'].update('') + + SearchKeyWord = values['-Search-'] + if event == 'Search': + with open("info.csv", 'r') as r: + FileReader = csv.reader(r) + for i in FileReader: + if i[1] == SearchKeyWord: + NewInfo = f"First Name:{i[0]}\nLast Name:{i[1]}\nPhone Number:{i[2]}\nPriority Level / Importance:{i[3]}\n" + #Reusing window[obj].update(value) to update the empty label -SearchOutput- + window['-SearchOutput-'].update(NewInfo) \ No newline at end of file