-2

I'm new to Tkinter and it's my understanding that we can't use threading with Tkinter. So I was wondering if there is an alternative to threading, or if there is a simple way to run a background timer?
Basically I want to replace the elements of my root with different elements after a certain amount of time without putting a stop to the execution of the program.
This is what I tried before I realized that threading is not an option in Tkinter:

def checkGridElements():
    time.sleep(5)
    label1.grid_forget()
    label2.grid(row=0,column=0,sticky=E,padx=5,pady=5);passEntry.grid(row=0,column=1,sticky=W,padx=5,pady=5)
    return

t = threading.Thread(target=checkGridElements)
t.start()
Arhaam Patvi
  • 409
  • 3
  • 10
  • Read [Run your own code alongside Tkinter's event loop](https://stackoverflow.com/questions/459083/how-do-you-run-your-own-code-alongside-tkinters-event-loop) and [use threads to preventing main event loop from “freezing”](https://stackoverflow.com/a/16747734/7414759) – stovfl Jan 26 '20 at 10:26

1 Answers1

0

The root (all widgets) has an after method which allows for a function to be called after a specified time, pausing the tk loop. If you are trying to use a thread, you might try tkthread (https://pypi.org/project/tkthread/). The problem is that python and tcl/tk have different threading systems. tkthread is supposed to bridge that.

  • It would be really helpful if you could show the implementation for `tkthread` in my case along with an explanation. I tried implementing it but I guess I'm doing something wrong and can't figure it out. – Arhaam Patvi Jan 26 '20 at 08:16