Hi all
I made this really simple program for myself to remind me to take some breaks.
It works great and all, although there is one behavior that I did not expect and although I don't mind it so much, i'd like to understand why it happens.
When the while loop is going and an interval variable is passed, the messagebox will come up. However, until I close the messagebox, it won't repeatedly come up multiple times. In fact I believe even the 'if' statement does not come into play again until I close that message box. My questions are:
I made this really simple program for myself to remind me to take some breaks.
It works great and all, although there is one behavior that I did not expect and although I don't mind it so much, i'd like to understand why it happens.
When the while loop is going and an interval variable is passed, the messagebox will come up. However, until I close the messagebox, it won't repeatedly come up multiple times. In fact I believe even the 'if' statement does not come into play again until I close that message box. My questions are:
- Shouldn't multiple messageboxes be coming up based on the if statement? Wouldn't the loop constantly be going, meaning multiple boxes come up?
- Does everything stop (including the loop) when the messagebox comes up?
import datetime as dt
from tkinter import *
def setInterval():
interval = dt.timedelta(minutes = int(entry_1.get()))
StartTime = dt.datetime.now()
while True:
if dt.datetime.now() == StartTime + interval:
messagebox.showinfo('STRETCH TIME',message = "Please take a stretch break!")
StartTime = dt.datetime.now()
if __name__ == "__main__":
root = Tk()
intervariable = IntVar()
theLabel = Label(root,text="Enter time below in minutes (e.g 30)")
theLabel.pack()
entry_1 = Entry(root)
entry_1.pack()
button_1 = Button(root,text="Set interval",command=setInterval)
button_1.pack()
root.mainloop()Appreciate any assistance :)
