'Is there a way to get win32api.GetKeyState to work within Tkinter?

I'm a novice programmer trying to use win32api to detect left mouse button presses. GetKeyState(0x01) has worked for me, but when I put it into my code, I believe it's interaction with tkinter makes it only result with 1.

class Bot:
    def __init__(self):
        stuff()

    def draw_box(self):
        while True:
            a = win32api.GetKeyState(0x01)
            print(a)
            time.sleep(0.1)
        
    def menu(self):
        root = Tk()
        root.geometry("500x500")

        b1 = Button(root,
                    text="Get Text",
                    command=self.draw_box)

        b2 = Button(root,
                    text="Type Text",
                    command=self.type_text)

        t1 = Text(root,
                  height=20,
                  width=50)

        t1.place(x=50, y=150)
        b1.place(x=55, y=50)
        b2.place(x=400, y=50)
        root.mainloop()

I would expect when b1 is pressed for it to correctly detect a left mouse button press, but it does not.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source