GUI Button hold down - tkinter

后端 未结 5 830
天命终不由人
天命终不由人 2020-12-06 15:50

I\'m trying to do a GUI in python to control my robotic car. My question is how I do a function that determine a hold down button. I want to move the car when the button is

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 16:08

    Try this...

    from Tkinter import *  
    root = Tk()
    global hold_down
    
    def button_hold(event):
        hold_down = True
        while hold_down: 
            print('test statement')
    
    def stop_motor(event):
        hold_down = False
        print('button released')
    
    button = Button(root, text ="forward")
    button.pack(side=LEFT)
    root.bind('',button_hold)
    root.bind('',stop_motor)
    root.mainloop()
    

提交回复
热议问题