Problem restricting textbox input to numbers only

Hello all,

(just as a disclaimer I have very little knowledge in Python).

I’ve been trying to restrict the keyboard input to a given textbox (line_textbox) to only numbers from 0 to 10 and nothing else.

I’ve looked through related topics here and try to implement the following code component suggested by @TParsons, referring to a keyboard component (key_resp_7) only allowing the keys above :

# what keys have been pressed this frame?
keys = key_resp_7.getKeys(keyList=['0','1','2','3','4','5',
'6','7','8','9'])
# if any, check that they're the right keys
if keys:
    if keys[-1] not in correctKeys:
        # if they're not valid, remove the last inputted character from the textbox
        line_textbox.text = line_textbox.text[0:-1]

This does not seem to work, and once it even crashed for some reason. Here’s an warning I get :

Alert 4405:Editable textbox component textbox and keyboard component key_resp_7 in the same routine may compete for keypresses

Would be grateful for some advice on this !

All the best,

Cameron