I have an initial value CamTimeObsVar = 50
and I want make it reducing as long as button btnCamTimeL is being pressed. When I release the button to stop reducing. I tried the following code but the variable reduced only once. Is it possible to control the changing speed? I tried sleep(0.1)
but it does not work.
Thanks in advance.
My code is:
from tkinter import *
from time import sleep
root = Tk()
root.geometry('800x480')
Pressed = False
def CamTimeObsVarL(event):
global CamTimeObsVar
print("Button is pressed")
CamTimeObsVar = CamTimeObsVar - 1
lblCamTime['text'] = str(CamTimeObsVar) + ' sec'
sleep(0.1)
def Stop(event):
global Pressed
print("Stopping")
Pressed = False
myFrame = Frame(root, width = 800, height=480)
CamTimeObsVar = 100
lblCamTime = Label(root)
lblCamTime.place(x=650, y=50)
lblCamTime['text'] = str(CamTimeObsVar) + ' sec'
btnCamTimeL = Button(root, text ='L', width=1, height=1, bg='red')
btnCamTimeL.place(x=620, y=50)
btnCamTimeL.bind('<ButtonPress-1>',CamTimeObsVarL)
btnCamTimeL.bind('<ButtonRelease-1>',Stop)
root.mainloop()