D
D
Danil Samodurov2020-06-02 21:30:41
Python
Danil Samodurov, 2020-06-02 21:30:41

How to make timer in tkinter window title?

Hello. I need to insert a countdown timer in the title of a window created with the tkinter library. So it's like this:

from tkinter import *

def countdown(t):
    pass

root = Tk()
root.title(countdown(60))
root.mainloop()

Where countdown(t) is a function that returns 1 less every second. Is this even possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2020-06-03
@samodurOFF

from tkinter import *

root = Tk()
t = 60
def countdown():
    global t, root
    root.title(str(t))
    if t==0: root.destroy()
    t-=1
    root.after(1000, countdown)

countdown()
root.mainloop()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question