#๐Ÿ”’ how do i make a timer in tkinter

32 messages ยท Page 1 of 1 (latest)

ivory folio
#

How do i mnake a timer doesnt need to be displayed can be in the background. Ive attempted to make one but could get the rest of my code to run as the timer is running how do i mkae a timer thawt runs at the same time

def startTimer(end):
    global timerNum
    if end != True: #manering the timer
        timerNum[2] = timerNum[2] + 1
        if timerNum[2] == 60:
            timerNum[2] = 0
            timerNum[1] += 1
            if timerNum[1] == 60:
                timerNum[1] = 0
                timerNum[0] += 1
        root.title(str(timerNum))
        root.after(1000, startTimer(False))
static snowBOT
#

@ivory folio

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

spiral karma
#

You need threads

ivory folio
#

What are they?

spiral karma
#

Running multiple executions at the same time

ivory folio
#

How do i uses threads?

spiral karma
#

Oh wait, you are using tkinter ?

ivory folio
#

Yes

spiral karma
#

You can do it differently

ivory folio
#

How can i do that?

spiral karma
#

Your idea make sense

ivory folio
#

It doest work

spiral karma
#

What is happening N

#

?

ivory folio
spiral karma
#

Yes okay, so the way you use after is incorrect

ivory folio
#
  File "/home/samms/PycharmProjects/FlasCards(ComputerSeince Revision/.venv/Scripts/Main.py", line 52, in startTimer
    root.after(1000, startTimer(False))
                     ^^^^^^^^^^^^^^^^^
  [Previous line repeated 992 more times]
RecursionError: maximum recursion depth exceeded**
```**
ivory folio
spiral karma
#

You need to give a function, and optionnaly some arguments

#

Here, you don't give a function, bc you execute the function

ivory folio
#

So i need a fuction to rerun the function?

spiral karma
#

I let you look at the documentation of after

ivory folio
#

Thanks

#

were can i find?

spiral karma
#

Google

ivory folio
#

Ill have a shearch

#

Thanks got everything to work now

#
**def addSecondToTimer():
    global timerNum
    print('test', timerNum)
    timerNum[-1] += 1
    startTimer(False)
def startTimer(end):
    global timerNum
    if end != True: #manering the timer
        if timerNum[2] == 60:
            timerNum[2] = 0
            timerNum[1] += 1
            if timerNum[1] == 60:
                timerNum[1] = 0
                timerNum[0] += 1

        root.after(1000, addSecondToTimer)
        root.title(str(timerNum))
#

close

#

!close

static snowBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.