I try to do it in a while loop with a boolean when the user pressed the button the boolean change to true and enter the while loop still the user released the button that put the boolean to false and exit the loop but in this code the boolean stay always true not matter if I released the button.
Code: Select all
from Tkinter import * hold_down = False root = Tk() def button_hold(event): hold_down=true while hold_down== True: print('test statement') hold_down = root.bind('<ButtonRelease-1>',stop_motor) def stop_motor(event): hold_down= False print('button released') button = Button(root, text ="forward") button.pack(side=LEFT) root.bind('<Button-1>',button_forward) root.mainloop()
I know this is a easy fix . Someone could help me. Thank
Edit: I want a function to be called repeatedly until a condition occurs. The function that I want to be called until the condition occurs is hold_down() that make the car run foward and the condition to check is the button is released.In other words while the button is pressed I want the function run_motor to be called repeatedly still I release the button, this is the condition to check. The problem with my code is always stays in the while loops printing 'test statememts' and doesn't check for the event button released.
If someone who watch this and have done what I want to do can kindly post a solution on how you do lt.
Update:I find a way to make it work . Thank.
note: English is not my native language