I'm trying to learn Python online from videos across the web. As a beginner project I chose to develope a simple system called POS (Point of Sale) with PySimpleGUI library.
There's a bug that I've been trying to fix for couple days. When I click cancel it moves back to the main window (worker window) but after selecting another worker it skips second window and moves to the third window (state window). If I repeat the same thing again, this time it moves to the fourth window.
Could you please explain me what am I doing wrong? Thank you.
import PySimpleGUI as sg
window_list = ["worker", "item", "state", "action"]
worker_list = ["worker_1", "worker_2", "worker_3"]
item_list = ["item_1", "item_2", "item_3", "item_4", "item_5", "item_6", "item_7"]
state_list = ["new", "kinda new", "old"]
action_list = ["buying", "selling"]
width, height = sg.Window.get_screen_size()
sg.theme("DarkAmber")
# window 1 - worker menu
workerButton = [ [ sg.Button("worker_1", size=(10, 5)), sg.Button("worker_2", size=(10, 5)), sg.Button("worker_3", size=(10, 5)) ],
[ sg.Button("EXIT", size=(10, 5)) ] ]
worker = sg.Window("CHOOSE A SELLER", workerButton, no_titlebar=False, size=(500, 500), keep_on_top=False)
# window 2 - item menu
itemButton = [ [ sg.Button("item_1"), sg.Button("item_2") ],
[ sg.Button("item_3"), sg.Button("item_4"), sg.Button("item_5"), sg.Button("item_6"), sg.Button("item_7") ],
[ sg.Button("CANCEL", size=(10, 5)) ] ]
item = sg.Window("CHOOSE AN ITEM", itemButton, size=(500, 500))
# window 3 - state menu
stateButton = [ [ sg.Button("new"), sg.Button("kinda new"), sg.Button("old") ],
[ sg.Button("CANCEL", size=(10, 5)) ] ]
state = sg.Window("CHOOSE A STATE", stateButton, size=(500, 500))
# window 4 - action menu
actionButton = [ [ sg.Button("buying"), sg.Button("selling") ],
[ sg.Button("CANCEL", size=(10, 5)) ] ]
action = sg.Window("CHOOSE AN ACTION", actionButton, size=(500, 500))
def ChoosingWorker():
event, values = worker.read()
if event in worker_list:
return event
else: # exit button
return "EXIT"
def ChoosingItem():
event, values = item.read()
if event == "item_1" or event == "item_2":
item.close()
return event # i was thinking another feature to item_1 and item_2 thats why i separatedly check it but i haven't coded yet
elif event in item_list:
item.close()
return event
else: # cancel button
item.close()
return event
def ChoosingState():
event, values = state.read()
if event in state_list:
state.close()
return event
else: # cancel button
state.close()
return event
def ChoosingAction():
event, values = action.read()
if event in action_list:
action.close()
return event
else: # cancel button
action.close()
return event
while True:
if ChoosingWorker() == "EXIT":
worker.close()
break
switch = 1
if switch == 1:
if ChoosingItem() == "CANCEL":
switch = 0
if switch == 1:
if ChoosingState() == "CANCEL":
switch = 0
if switch == 1:
if ChoosingAction() == "CANCEL":
switch = 0