I am trying to implement a button that continuously runs steps of my game. The button involves an infinite loop that runs my step function over and over until the button is released. Problem is it doesn't work. Instead it usually freezes or gives me
TypeError: <lambda>() takes 0 positional arguments but 1 was given
Here is the code:
def __init__(self, root):
Frame.__init__(self, root)
self.butt_released = False
button3 = Button(self.but_frame, text='Step', width=15, command=lambda :self.step_funct())
button3.pack(side='right')
button4 = Button(self.but_frame, text='Run', width=15)
button4.pack(side='right')
button4.bind("<Button-1>", lambda :self.run_funct())
button4.bind("<ButtonRelease-1>", lambda :self.butt_release())
def run_funct(self):
while True:
self.step_funct()
time.sleep(1)
if self.butt_released:
break
self.butt_released = False
def butt_release(self):
self.butt_released = True
If anyone can help me fix this then that would be great.