Reputation: 11
I'm trying to validate user input. A popup is triggered when incorrect data entered. My app then closes but I want it to return user to main page to modify input. Tks, Ian
while True:
event, values = window.read() #values is a list in Python
if event == 'Exit':
break
elif event == 'Submit':
#input_valid = False
#while not input_valid:
validation_result = validate_inputs(values) #returns array of [is_valid[bool],invalid_values[array]
if validation_result[0]:#if True
string_of_rpt_date = calculate_repeat_date(values) #function takes interval value inputted and returns next repeat as sting
c.execute("INSERT INTO PATIENT(SURNAME,FIRST_NAME,ADDRESS,DOB,MOBILE,PPS,DOCTOR,REPEAT_INTERVAL,REPEATS_LEFT,REPEAT_DATE) \
VALUES (?,?,?,?,?,?,?,?,?,?)",(values['-SURNAME-'],values['-FIRST_NAME-'],values['-ADDRESS-'],values['-DOB-'],values['-MOBILE-'],values['-PPS-'],values['-DOCTOR-'],values['-REPEAT_INTERVAL-'],values['-REPEATS_LEFT-'],string_of_rpt_date))
conn.commit()
c.execute("SELECT * FROM PATIENT WHERE REPEAT_DATE = ?", (string_of_today,)) #checks database to see if any patients repeat date is today
results = c.fetchall()
for row in results:
mobile = row[4]
first_name = row[1]
repeats_left = row[8]
repeats_left = repeats_left -1
c.execute("UPDATE PATIENT SET REPEATS_LEFT =? WHERE FIRST_NAME = ?", (repeats_left,first_name,))
conn.commit()
print(mobile)
print(repeats_left)
print(first_name)
print(results)
#flow_twilio(first_name,repeats_left) # this function sends msg via twilio
# to let patient know repeat is due
# and how many repeats are left"""
conn.close()
#whatsapp_twilio(mobile, first_name, repeats_left )
#text_twillio(mobile, first_name, repeats_left)
sg.popup(values['-FIRST_NAME-'] + ' ' + values['-SURNAME-'] + ' was added to the database')
else:
error_message = generate_error_message(validation_result[1])
sg.popup(error_message, auto_close=True)#popup of elements of invalid_values array
if event == sg.WIN_CLOSED:
break
window.close()
I tried adding a while loop just after the submit button is pressed as follows elif event == 'Submit': but this didn't work either.
I'm relatively new to coding so not sure where to go next. Any help appreciated
Upvotes: 0
Views: 38