Sep-22-2021, 03:02 PM
Hello,
Please see complete code below. The issue is, when you load the program, you can go to the "Open Requests" tab and it works, however if you go onto any other tab, and then click on the "Open Requests" tab, it crashes. This is the same when you go from the "Open Requests" tab, back into it.
The code should make it reset but there is no error message, the program just stops responding. I'm aware there is a lot of code (At least from my point of view), but i thought it best to include the whole thing.
Everything else works, so I believe it is an issue in the last function, which works the "Open Requests" tab.
Please see complete code below. The issue is, when you load the program, you can go to the "Open Requests" tab and it works, however if you go onto any other tab, and then click on the "Open Requests" tab, it crashes. This is the same when you go from the "Open Requests" tab, back into it.
The code should make it reset but there is no error message, the program just stops responding. I'm aware there is a lot of code (At least from my point of view), but i thought it best to include the whole thing.
Everything else works, so I believe it is an issue in the last function, which works the "Open Requests" tab.
import PySimpleGUI as sg import csv from csv import reader import sqlite3 sg.theme("DarkAmber") entry = [] equipm = [] a = "" ti = [] t = [810,390] p = ("") xy = "NA" yz = "NA" zx = "NA" admins = [["Admin","Administrator"],["Admin","OneTwoTree"]] con = sqlite3.connect(r'equipment.db') # FIGURE OUT HOW TO ACCESS SHARED DRIVE !# cur = con.cursor() def startup(): for row in cur.execute('SELECT * FROM user_equipment'): entry.append(row) login() def login(): global b layout0 = [[sg.T("")],[sg.T("Admin Login",font=("arial,15"))],[sg.T("Username")],[sg.InputText(key = "usr")],[sg.T("Password")],[sg.InputText(key = "pwd")],[sg.Button("OK", bind_return_key = True)],[sg.T("")],[sg.T("")],[sg.B("Guest Login")]] window0 = sg.Window("IT Portal", layout0, location=(t[0],t[1]), size = (600,500),finalize = True) event,values = window0.read() t.clear() while True: if event == sg.WIN_CLOSED: break if event == "OK": u = window0.CurrentLocation() t.append(u[0]) t.append(u[1]) b = str(values['usr']) c = str(values['pwd']) if b in admins[0] and c in admins[1]: window0.close() main() break if b not in admins or c not in admins: sg.popup('Invalid Login.','Please try again.', location = (t[0],t[1])) window0.close() login() break if event == "Guest Login": u = window0.CurrentLocation() window0.close() t.append(u[0]) t.append(u[1]) guestmain() break #########################################################################GUEST SECTION######################################################################### def guestmain(): layout10 = [[sg.T("")],[sg.B("Request Equipment"),sg.B("Raise Ticket")]] window10 = sg.Window("Guest Portal", layout10,location = (t[0],t[1]), size = (600,500),finalize = True) event, values = window10.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "Request Equipment": u = window10.CurrentLocation() window10.close() t.append(u[0]) t.append(u[1]) equipreq() break if event == "Raise Ticket": u = window10.CurrentLocation() window10.close() t.append(u[0]) t.append(u[1]) newticket() break def newticket(): layout11 = [[sg.T("")],[sg.B("Request Equipment"),sg.B("Raise Ticket")],[sg.T("")],[sg.T("Topic:"),sg.T(" "),sg.T("Issue Description:")],[sg.Combo(values = ("Office Products","Other"),key = "D"),sg.Multiline(size = (45,5),key = "E")], [sg.T("Email Address:")],[sg.InputText(key="F")],[sg.T("")],[sg.T("")],[sg.B("Submit Ticket"),sg.T("Please include as much information as you can.")]] window11 = sg.Window("Guest Portal",layout11,location=(t[0],t[1]),size=(600,500), finalize = True) event,values = window11.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "Request Equipment": u = window11.CurrentLocation() window11.close() t.append(u[0]) t.append(u[1]) equipreq() break if event == "Raise Ticket": u = window11.CurrentLocation() window11.close() t.append(u[0]) t.append(u[1]) newticket() break if event == "Submit Ticket": x = values["D"] y = values["E"] z = values["F"] ti = [] for row in cur.execute('select * from tickets'): ti.append(row) cur.execute('INSERT INTO tickets values('+ str(len(ti)+1) +',"'+ str(x) + '","' + str(y[:-1])+ '",' + "false" + ',"' + str(z) + '")') con.commit() u = window11.CurrentLocation() t.append(u[0]) t.append(u[1]) window11.close() newticket() break def equipreq(): layout12 = [[sg.T("")],[sg.B("Request Equipment"),sg.B("Raise Ticket")],[sg.T("")],[sg.T("Name:")],[sg.InputText(key="G")],[sg.T("")],[sg.T("Equipment Type:")],[sg.Combo(values = ("Monitor","Screen","Mobile","Desktop","Laptop","Mouse/Keyboard","Other"),key="H")],[sg.T("If you selected 'Other' please specify in the box below.")],[sg.T("Please say why you need the equipment:")],[sg.Multiline(size=(45,5),key="I")],[sg.T("")],[sg.T("")],[sg.B("Submit")]] window12 = sg.Window("Guest Portal", layout12,location = (t[0],t[1]), size = (600,500), finalize = True) event,values = window12.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "Request Equipment": u = window12.CurrentLocation() window12.close() t.append(u[0]) t.append(u[1]) equipreq() break if event == "Raise Ticket": u = window12.CurrentLocation() window12.close() t.append(u[0]) t.append(u[1]) newticket() break if event == "Submit": x = values["G"] y = values["H"] z = values["I"] ti = [] for row in cur.execute('select * from equip_request'): ti.append(row) cur.execute('INSERT INTO equip_request values('+ str(len(ti)+1) + ',"' + str(x) + '","' + str(y) + '","' + str(z[:-1])+'")') con.commit() u = window12.CurrentLocation() window12.close() t.append(u[0]) t.append(u[1]) equipreq() break #########################################################################END OF GUEST SECTION######################################################################### #########################################################################ADMIN SECTION######################################################################### def main(): layout1 = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")]] window1 = sg.Window("IT Admin Portal", layout1,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window1.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() user_list() break if event == "View Logged Equipment": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() out_equipment() break if event == "Log Equipment Out": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() new_entry() break if event == "Open Tickets": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() tickets() break if event == "Open Requests": u = window1.CurrentLocation() t.append(u[0]) t.append(u[1]) window1.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break def user_list(): entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) user = [] user.append(entry[0][1]) x = 0 global a for x in range(len(entry)): if entry[x][1] not in user: user.append(entry[x][1]) x += 1 x += 1 user_list1 = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T("")], [sg.Listbox(values=user,size = (30,10),key = "userid")],[sg.Button("Select", bind_return_key = True)]] window2 = sg.Window("IT Admin Portal - User List", user_list1,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window2.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() user_list() break if event == "View Logged Equipment": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() out_equipment() break if event == "Open Tickets": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() tickets() break if event == "Log Equipment Out": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() new_entry() break if event == "Select": a = str(values['userid']) u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() user_equip() break if event == "Open requests": u = window2.CurrentLocation() t.append(u[0]) t.append(u[1]) window2.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break def user_equip(): equip = [] serial = [] x = 0 entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) global a for x in range(len(entry)): if a[2:5] in entry[x][1]: equip.append(entry[x][2]) serial.append(entry[x][3]) x += 1 user_list2 = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T(a)],[sg.T("Type"),sg.T(" "),sg.T("Serial")], [sg.Listbox(values=equip,size = (10,10),key = "user_equip"),sg.Listbox(values=serial,size=(33,10),key = "D")],[sg.T("")],[sg.T("")],[sg.T("An equipment return form must be filled out, scanned and saved.")],[sg.T("Select the serial number of the returned item.")],[sg.Button("Return")]] window3 = sg.Window("IT Admin Portal - User Details", user_list2,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window3.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() user_list() break if event == "View Logged Equipment": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() out_equipment() break if event == "Log Equipment Out": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() new_entry() break if event == "Open Tickets": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() tickets() break if event == "Return": entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) z = str(values["D"]) u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) for y in range(len(entry)): if z[2:-2] == entry[y][3]: cur.execute('delete from user_equipment where serial="'+str(entry[y][3])+'";') con.commit() window3.close() entry.clear() login() break if event == "Open requests": u = window3.CurrentLocation() t.append(u[0]) t.append(u[1]) window3.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break def new_entry(): new_ntr = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T("")], [sg.T("Name")],[sg.InputText(key = "A")],[sg.T("Equipment Type")],[sg.Combo(values = ("Monitor","Desktop","Laptop","Mobile"),size=(15,15),key = "B")],[sg.T("Serial")],[sg.InputText(key = "C")],[sg.T("")],[sg.T("")], [sg.T("")],[sg.T("An issue form must also be filled out, scanned, and saved.")],[sg.Button("Save", bind_return_key = True)]] window5 = sg.Window("IT Admin Portal - Log Equipment Out", new_ntr,location = (t[0],t[1]), size = (600,500), finalize = True) event, values = window5.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() user_list() break if event == "View Logged Equipment": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() out_equipment() break if event == "Log Equipment Out": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() new_entry() break if event == "Open Tickets": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() tickets() break if event == "Save": entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) x = values["A"] y = values["B"] z = values["C"] a = int(len(entry)+1) cur.execute('insert into user_equipment values('+ str(a) + ',"' + x + '","' + y + '","' + z + '");') con.commit() entry.clear() u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() startup() break if event == "Open requests": u = window5.CurrentLocation() t.append(u[0]) t.append(u[1]) window5.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break def out_equipment(): entry.clear() for row in cur.execute('select * from user_equipment'): entry.append(row) mob = 0 des = 0 lap = 0 mon = 0 global p global equipm equip = [] for x in range(len(entry)): if "Mon" in entry[x][2]: mon += 1 if "Des" in entry[x][2]: des += 1 if "Lap" in entry[x][2]: lap += 1 if "Mob" in entry[x][2]: mob += 1 out_equip = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T("")], [sg.T("Monitors"),sg.T(" "),sg.T("Desktops"),sg.T(" "),sg.T("Laptops"),sg.T(" "),sg.T("Mobiles")], [sg.T(" " +str(mon)+ " "),sg.T(" " +str(des)+ " "),sg.T(" " +str(lap)+ " "),sg.T(" " +str(mob))],[sg.T("")],[sg.T("")],[sg.T("")],[sg.T("")], [sg.Combo(values = ("Monitor","Desktop","Laptop","Mobile"),default_value=("Filter by"),key = "filterby"),sg.T(p)],[sg.Button("Filter"),sg.Listbox(values = equipm, size = (35,10))]] window4 = sg.Window("IT Admin Portal - View Logged Equipment", out_equip,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window4.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "User List": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() user_list() break if event == "View Logged Equipment": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() out_equipment() break if event == "Log Equipment Out": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() new_entry() break if event == "Filter": equipm = [] z = values["filterby"] p = values["filterby"] for x in range(len(entry)): if z in entry[x]: equipm.append(entry[x][1]) equipm.append(entry[x][3]) x += 1 u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() out_equipment() break if event == "Open Tickets": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() tickets() break if event == "Open requests": u = window4.CurrentLocation() t.append(u[0]) t.append(u[1]) window4.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break def tickets(): global ti ti = [] for row in cur.execute('select * from tickets where open_close = false'): ti.append(row) layout12 = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T("")],[sg.Listbox(values = ti, size = (60,10),key="J"),sg.B("Select")]] window12 = sg.Window("IT Admin Portal - Open Tickets", layout12,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window12.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "Open Tickets": u = window12.CurrentLocation() t.append(u[0]) t.append(u[1]) window12.close() tickets() break if event == "User List": u = window12.CurrentLocation() t.append(u[0]) t.append(u[1]) window12.close() user_list() break if event == "View Logged Equipment": u = window12.CurrentLocation() t.append(u[0]) t.append(u[1]) window12.close() out_equipment() break if event == "Log Equipment Out": u = window12.CurrentLocation() t.append(u[0]) t.append(u[1]) window12.close() new_entry() break if event == "Select": u = window12.CurrentLocation() t.append(u[0]) t.append(u[1]) ti.clear() ti = values["J"] if len(ti) < 1: sg.popup("Invalid Selection","Please select a ticket",location = (t[0],t[1])) tickets() window12.close() selection() break if event == "Open requests": u = window12.CurrentLocation() t.append(u[0]) t.append(u[1]) window12.close() xy = "NA" yz = "NA" zz = "NA" requestlist() break def selection(): global ti layout13 = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T("")],[sg.T("ID: "),sg.T(ti[0][0])],[sg.T("Topic: "),sg.T(ti[0][1])],[sg.T("Issue: "),sg.T(ti[0][2])],[sg.T("Name: "),sg.T(ti[0][4])],[sg.B("Clear")]] window13 = sg.Window("IT Admin portal - View Ticket", layout13,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window13.read() t.clear() while True: if event == sg.WIN_CLOSED: con.close() break if event == "Open Tickets": u = window13.CurrentLocation() t.append(u[0]) t.append(u[1]) window13.close() tickets() break if event == "User List": u = window13.CurrentLocation() t.append(u[0]) t.append(u[1]) window13.close() user_list() break if event == "View Logged Equipment": u = window13.CurrentLocation() t.append(u[0]) t.append(u[1]) window13.close() out_equipment() break if event == "Log Equipment Out": u = window13.CurrentLocation() t.append(u[0]) t.append(u[1]) window13.close() new_entry() break if event == "Clear": u = window13.CurrentLocation() t.append(u[0]) t.append(u[1]) window13.close() cur.execute('update tickets set open_close = true where id = '+str(ti[0][0])+';') con.commit() ti.clear() tickets() break if event == "Open requests": u = window13.CurrentLocation() t.append(u[0]) t.append(u[1]) window13.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break def requestlist(): req = [] requ = [] global xy global yz global zx for row in cur.execute('select * from equip_request;'): req.append(list(row)) if len(req) > 0: for row in range(len(req)): requ.append(str(req[row][1])) layout14 = [[sg.T("")],[sg.Button("View Logged Equipment"),sg.Button("User List"),sg.Button("Log Equipment Out"),sg.B("Open Tickets"),sg.B("Open Requests")],[sg.T("")],[sg.T("")],[sg.T("Requests for equipment:")],[sg.Listbox(values = (requ),size = (15,10),key = "K"),sg.B("Details")],[sg.T("Details: ")],[sg.T("Name: "+str(xy))],[sg.T("Equipment Requested: "+str(yz))],[sg.T("Reason: "),sg.Multiline(default_text=str(zx))]] window14 = sg.Window("IT Admin Portal - View Open Requests", layout14,location=(t[0],t[1]), size = (600,500), finalize = True) event, values = window14.read() t.clear() xy = "NA" yz = "NA" zx = "NA" while True: if event == sg.WIN_CLOSED: break if event == "Details": q = str(values["K"]) for f in range(len(req)): if q[2:-2] in req[f]: xy = str(req[f][1]) yz = str(req[f][2]) zx = str(req[f][3]) u = window14.CurrentLocation() t.append(u[0]) t.append(u[1]) window14.close() requestlist() break if event == "Open Tickets": u = window14.CurrentLocation() t.append(u[0]) t.append(u[1]) window14.close() tickets() break if event == "User List": u = window14.CurrentLocation() t.append(u[0]) t.append(u[1]) window14.close() user_list() break if event == "View Logged Equipment": u = window14.CurrentLocation() t.append(u[0]) t.append(u[1]) window14.close() out_equipment() break if event == "Log Equipment Out": u = window14.CurrentLocation() t.append(u[0]) t.append(u[1]) window14.close() new_entry() break if event == "Open requests": u = window14.CurrentLocation() t.append(u[0]) t.append(u[1]) window14.close() xy = "NA" yz = "NA" zx = "NA" requestlist() break #########################################################################END OF ADMIN SECTION######################################################################### startup()