Turtle Problems when using both numinput() and onkeypress()

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:

sc.onkeypress(play,           "space")
sc.onkeypress(showHelp,       "h")
sc.onkeypress(quit,           "q")

rawval = turtle.numinput("Set the Speed", "Speed ( 1 ... 10 ): ", default=5, minval=0, maxval=10)
ball.speed(rawval)
play()

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 may be a bug is numinput cancels onkeypress or if that is not ducumented. However, what happens if you do the onkeypress stuff after the numinput?

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.

I’ve shrunk my code for easier demo.
I am running it on Linux Mint 21.2 with Python 3.13.0a1. Same outcome with Python 3.10.12.

#! /usr/bin/env python3
# -*- coding: UTF-8 -*-

"""
test_numinput.py
"""

import turtle

rawval = turtle.numinput("Kreise malen", "Anzahl der Kreise: ", default=11, minval=None, maxval=None)
print("numinput: ", rawval)

# create screen
sc = turtle.Screen()
sc.setup(width=1000, height=600)
sc.listen()

# create blue pad turtle
BluePad = turtle.Turtle()


def play():
    print("You pressed 'Space'")


def init():
    # Keyboard bindings
    sc.onkeypress(play,             "space")

    # show Left (Blue) paddle
    BluePad.shape("square")
    BluePad.color("blue")
    BluePad.shapesize(stretch_wid=1, stretch_len=10)
    BluePad.st()


def main():

    ###
    ### now working; remove comment from next line to see failing onkeypress()
    # rawval = turtle.numinput("Kreise malen", "Anzahl der Kreise: ", default=22, minval=None, maxval=None)
    ###
    print("numinput: ", rawval)

    init()
    while True:
        sc.update()
        if False: break

main()
turtle.bye()