0

I have a gui that needs to have the information in its labels refresh every so often and I have a function that would do so. I was wondering how can i call that function every 10 seconds automatically.

Currently I have a button that refreshes the information but that has to be manually pressed.

bRefreshSystem = tk.Button(text="System Refresh", command=refreshSystem)

Currently my solution does work but its not optimal, so how can i call refreshSystem automatically every 10 seconds?

Legorooj
  • 2,533
  • 2
  • 14
  • 31
Ori Levy
  • 81
  • 6

2 Answers2

1

No need for threads, the simplest is to use root.after:

def refreshSystem():
    do stuff
    root.after(10000, refreshSystem)   # the delay is in milliseconds
Reblochon Masque
  • 33,202
  • 9
  • 48
  • 71
0

You could launch a thread to run a function every n seconds. Would that work for you?

import threading

def do_something():
  print("Hello!")
  threading.Timer(5, do_something).start()

do_something()
João Matos
  • 91
  • 1
  • 8