1

everything is working for now but I need to signify good input by flashing the entry box green for ~0.5 sec without blocking the ongoing animation.

I create an entry box using the following code

```python

p = tkinter.Entry(master=root, placeholder_text=P_TGT, width=100)
p.bind("<Return>", update_p)
p.bind("<FocusOut>", update_p)

```

where update_p() executes the following -

```python

p.configure({"foreground": "green"})) #signifies good input
time.sleep(5)
p.configure({"foreground": "white"}) #reset color

```

but this code blocks the execution of the whole app, how do i execute such a startegy without blocking the ongoing animation in tkinter?

Thanks

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Saqster
  • 119
  • 1
  • 1
  • 8

1 Answers1

2

Tkinter widgets have a method named after which can be used to schedule code to run in the future. after takes as arguments a timeout in milliseconds, a callable, and zero or more positional arguments. The callable will be called with the given arguments as soon as possible after the timeout has been reached.

In your case you can use it to change the color back to white after one second like in the following example.

def update_p():
    p.configure({"foreground": "green"}) #signifies good input
    p.after(1000, p.configure, {"foreground": "white"})
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685