Search code examples
pythonloopstkintercrashpywin32

Tkinter and win32api, while True crashes app


im working with tkinter and win32api. I've declared the next function:

def on_press():
        leftBtn = 0x01
        key = win32api.GetKeyState(leftBtn)
        if key < 0:
                print("Left click pressed")
                time.sleep(0.1)
                root.after(100,on_press)
        
root.after(100,on_press)

Already tried to do the .after to don't have two infinite loops but still crashing. Any answer??

Git to my project (not finished...): https://github.com/alexcibubins/NoRecoilScript-notFinished-.git


Solution

  • def on_press():
            leftBtn = 0x01
            key = win32api.GetKeyState(leftBtn)
            if key < 0:
                    print("Left click pressed")
                    time.sleep(0.1)
            root.after(100, on_press)
            
    root.after(100,on_press)