0

I need to create a timer with Tkinter. I'd like to know a simple way and easy way. Here is my code. It doesn't work though. and I don't wanna use class. (def is OK)

import tkinter as tk
import os
import time
root = tk.Tk()
def Timer():
  s=0
  m=0
  while s<=60:
    os.system('cls')
    label=(text= m, 'Minutes', s, 'Seconds')
    time.sleep(1)
    s+=1
    if s==60:
        m+=1
        s=0
Timer()
label = tk.Label(root,justify="center")
label.pack()
root.mainloop()
Takahiro
  • 3
  • 3
  • "It doesn't work though." What happens when you run the code? How is this different from what is supposed to happen? – Karl Knechtel Nov 22 '20 at 17:51
  • Thanks for your comment. My image is to display a timer in the label(or frame). But now the timer opens in the console. – Takahiro Nov 23 '20 at 14:31
  • Yes, that is what `print` does. To change the text on the Label, you must... change the text on the Label. Did you try to search for `tkinter label text` or something like that? I found [this](https://www.geeksforgeeks.org/how-to-change-the-tkinter-label-text/) result easily, for example. – Karl Knechtel Nov 23 '20 at 14:56
  • However, it is also necessary to use tkinter's event loop instead of using `.sleep` in the main thread for timing. The duplicate will show you how. – Karl Knechtel Nov 23 '20 at 14:57
  • OMG. cant understand. it would be faster if you show me the code lol. Help me, anybody!! – Takahiro Nov 23 '20 at 15:59
  • Do you see at the top where it says "This question already has answers here: How to create a timer using tkinter? (7 answers)"? Did you try clicking the link? Did you try reading the answers there, which include code? – Karl Knechtel Nov 23 '20 at 20:26
  • If reading full answers to someone else asking the same question does not help you, then how can anything else help you? – Karl Knechtel Nov 24 '20 at 17:53
  • Show me the code referencing my code if you now how to create a timer as I said. – Takahiro Nov 25 '20 at 04:47

0 Answers0