I have a function that takes in a start time and end time of an activity. I would like a message box to pop up to tell them if the start time begins after the end time (for example starting at 18.00 but finishing at 15.00). I decided that a message box would be perfect for telling them they are wrong and pushing them back to the beginning of the function.
How would I be able to make the button that when pressed, calls two commands. One that goes back to the beginning of the function and another that destroys the message box?
hour1 = variable_st.get()
starttimehour = str(datetime.time(hour1,minute,second))
hour2 = variable_end.get()
endtimehour = str(datetime.time(hour2,minute,second))
if starttimehour >= endtimehour:
win = Toplevel()
message = "You have selected invalid input. Please try again"
Label(win, text = message).pack()
button = Button(win, text = 'ok', command = addtimeslot AND win.destroy).pack
btn_add_final = ttk.Button(window1, text = "Add timeslot",width = 15, command = addtimeslot)
Make a function that calls both of your functions:
def fun1_and_fun2(): fun1() fun2() # Function holding your button # Stuff # .... button = Button(win, text = 'ok', command = fun1_and_fun2).pack