I'd like to make a graphic window in PyDev (Eclipse) python 2.75.
I've done few things but I'd like to make an "entrance" "blink". It's Tests the user input.
If it's an integer it should blink green for a second, and then turn into white. But if it's a string of something else it should blink red, and then turn into white. I've used a time.sleep()
but it doesn't work as I'd like to.
Here is my code for this action:
def sprawdzam():
z = e.get()
try:
z = int(z)
e.config(bg = 'green')
time.sleep(2)
e.config(bg = 'white')
except:
l.config(bg = 'red')
time.sleep(2)
e.config(bg = 'white')
If you've got a Python program and you want to make it wait, you can use a simple function like this one: time. sleep(x) where x is the number of seconds that you want your program to wait.
The after() method calls the callback function once after a delay milliseconds (ms) within Tkinter's main loop. If you don't provide the callback , the after() method behaves like the time. sleep() function. However, the after() method uses the millisecond instead of the second as the unit.
time.sleep
blocks the execution of the program.
Use after
.
For example:
from Tkinter import *
def blink():
e.config(bg='green')
e.after(1000, lambda: e.config(bg='white')) # after 1000ms
root = Tk()
e = Entry(root)
e.pack()
b = Button(root, text='blink', command=blink)
b.pack()
root.mainloop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With