-1

So in my program I'm using tkinter to handle my key presses However my program runs in a tick loop and I've found out that my programs tick loop and tkinters main loop are clashing with eatch other. Is there a way to fix this? Dose tkinter have a function that dose a single loop that I could call on eatch of my ticks? If not then what would you recommend replacing tkinter with to handle key pressing?

skyzzle
  • 167
  • 1
  • 4
  • 16

1 Answers1

0

I've dealt with the same issue :)

You can achieve what you want using tkinter's after() and after_idle() functions.

For example, a loop function can look like that:

def loop(self):
    #  do whatever your tick loop needs to to
    self.cyclesId = self.after_idle(self.loop)

You can call it only once and it will be called again every iteration of tkinter's mainloop().

galah92
  • 3,621
  • 2
  • 29
  • 55