I am beginning to use turtle for educational purposes, and stumble over this problem in coding a “Pong” like game: I cannot use both numinput() and onkeypress() in the same code. This is the relevant code segment:
The numinput() by itself works correctly and returns the number entered via the keyboard. But all onkeypress() commands no longer work: just no response whatsoever on pressing space, h, or q.
Commenting out the numinput() line and all works well; I just can’t modify the speed value.
Am I doing it wrongly, or is that a consequence of tkinter running in the background? And if so, how can I make the code accept a number entered from the keyboard?
It sounded like a weird idea but I checked anyway … and proved your suspicion right!
When the numinput command (as shown in my first post) was positioned at the very beginning, right after the import commands, all worked as it should.
When the numinput command was placed as the first thing in main(), no key presses were ever detected! At this point, onkeypress() commands had been defined in subroutines, but none had been executed.
When the numinput command was placed in both locations, numbers could be put in in both, but again, no keypresses were detected.