-1

I have a tkinter GUI form which now showing some text from text file. Now i have a countdown module as below:

def countdown(t):
 while t:
    mins, secs = divmod(t, 60)
    timeformat = '{:02d}:{:02d}'.format(mins, secs)
    print(timeformat, end='\r')
    time.sleep(1)
    t -= 1

How can i show this countdown at tkinter tittle which show the time left for program reload ?

Thanks

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
aht acs
  • 13
  • 1
  • there are probably dozens of questions on this site related to creating counters with tkinter. Please do a little research before asking such a broad, basic questino. – Bryan Oakley May 03 '18 at 13:58
  • 2
    Possible duplicate of [Making a countdown timer with Python and Tkinter?](https://stackoverflow.com/questions/10596988/making-a-countdown-timer-with-python-and-tkinter) – divibisan May 03 '18 at 14:11
  • I have already have countdown code, just want to make it work for showing on tittle. There is no answer there – aht acs May 03 '18 at 14:55
  • @ahtacs I have added an answer showing how. – Artemis May 03 '18 at 19:41

1 Answers1

0

Here is a short program that updates the title according to your code:

import time
from tkinter import *
def changeTitle(root, val, t):
    root.title(val)
    root.after(1000, lambda:countdown(t-1, root))
def countdown(t, root):
     if t+1:
         mins, secs = divmod(t, 60)
         timeformat = '{:02d}:{:02d}'.format(mins, secs)
         changeTitle(root, timeformat, t)
     else:
         return
root=Tk()
countdown(10, root)
mainloop()
Artemis
  • 2,553
  • 7
  • 21
  • 36