How to detect if a user has typed an integer on their keyboard in pygame?

Solution 1:

You could convert the keycode to it's representing character, then check if it is a digit with isdigit().

if event.type == pygame.KEYDOWN:
    if pygame.key.name(event.key).isdigit():
        pass # Do stuff