Python Forum
Tkinter messagebox and using datetime/timedelta
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter messagebox and using datetime/timedelta
#1
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:
  • 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 :)
Reply


Messages In This Thread
Tkinter messagebox and using datetime/timedelta - by Kaltex - Apr-07-2021, 04:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Sound from the tkinter.messagebox tedarencn 2 6,094 Jul-11-2020, 10:45 AM
Last Post: steve_shambles
  [Tkinter] Messagebox with playsound khandelwalbhanu 6 4,525 May-16-2020, 11:40 AM
Last Post: chesschaser
  [Tkinter] messagebox is not being executed please help erwinsiuda 2 2,383 Apr-02-2020, 01:56 AM
Last Post: Larz60+
  [Tkinter] passing data to messagebox kmusawi 0 1,867 Feb-18-2019, 01:51 AM
Last Post: kmusawi
  Adding timer on the Messagebox aniyanetworks 6 11,962 Feb-13-2019, 07:48 PM
Last Post: aniyanetworks
  [Tkinter] Button widget gets stuck from using tkinter.messagebox? Nwb 2 4,018 Jun-20-2018, 02:21 PM
Last Post: Nwb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020