Program was working fine until I added the Start button on the bottom. Program seems to be running properly except that the timer doesn't update. I would like the counter to start counting down as soon as the "Start" button is clicked in my program.
My code:
import time
import tkinter as tk
def DisplayCountdown():
# Time
m = 0
s = 3
print('Running DisplayCountdown function')
if m == 0 and s == 0:
count_down_display.configure(text='Stand up!')
elif s == 0:
s=59
m-=1
count_down_display.after(1000, DisplayCountdown)
else:
s-=1
countdown_display.configure(text='%s minutes %s seconds' % (m,s))
countdown_display.after(1000, DisplayCountdown)
# Window
window = tk.Tk()
window.title('Stand Up Timer')
window.configure(bg = 'black')
# Information label
start_label = tk.Label(window,
font = 'ariel 40',
bg = 'black',
fg = 'red',
text = 'Click the start button to begin the timer.')
start_label.grid(row = 0, column = 0)
# Display Countdown
countdown_display = tk.Label(window,
font = 'ariel 40',
bg = 'black',
fg = 'red',
text = 'Countdown displayed here!')
countdown_display.grid(row = 1, column = 0)
# Start button
start_button = tk.Button(window,
text='Start',
command=DisplayCountdown)
start_button.grid(row = 2, column = 0)
# Window main loop
window.mainloop()