Tkinter gui doesn't work Mouse and keyboard modules Tkinter gui doesn't work Mouse and keyboard modules tkinter tkinter

Tkinter gui doesn't work Mouse and keyboard modules


The reason why GUI does not show up is that before the code hits mainloop() it goes into a infinite loop(while loop) and it cannot reach mainloop and hence window does not show up and events are not processed. So what you should do is get rid of while. One way is to use after() method to emulate while.

def joesd(self):    if kb.is_pressed('q'):        ms.press('left')        ms.release('left')            self.after(100,self.joesd)

This will repeat the function every 100 ms, you can reduce it to 1ms too. But make sure it is not too much for the system to handle.


You should not use while loop in a tkinter application. You can register a callback using kb.on_press_key() instead:

class Application(tk.Frame):    def __init__(self, master=None):        super().__init__(master)        ...        #self.joesd() # <- not necessary        kb.on_press_key("q", self.on_key_press)    ...    def on_key_press(self, event):        #print("q pressed", event)        ms.press('left')        ms.release('left')        # above two lines can be replaced by ms.click('left')