Renderizar una lista en basicfont.render en python

I am trying to make it so you can type into a specified box in python (not using the inputbox module), and am trying to render a list into text. Here is the section of code :

    TypingUsername = []
    for event in pygame.event.get():
        KeyPressed = pygame.key.get_pressed()
    LoginUsernameInput = basicFont.render('%d' %(TypingUsername), True, White, Black)

I am unsure of what to put into my basicFont.render ('%????') to import the list TypingUsername ('d' is my placeholder for right now'). If anyone could help me, that would be tremendous help!

preguntado el 27 de noviembre de 13 a las 05:11

Learn more about events. -

1 Respuestas

Cuándo event.type is pygame.KEYDOWN you can get only pressed key (event.key) and add to result string.

TypingUsername = ""

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN
        TypingUsername += event.key

LoginUsernameInput = basicFont.render(TypingUsername, True, White, Black)

Learn more about events: pygame.event

por cierto names with first upper letter should be use as class names - see Convenciones de nombres in PEP 8. So use typingUsername o incluso typing_username, login_username_input. Constants like White should be in capital letters - WHITE, BLACK, KEYDOWN

typing_username = ""

for event in pygame.event.get():
    if event.type == pygame.KEYDOWN
        typing_username += event.key

login_username_input = basicFont.render(typing_username, True, WHITE, BLACK)

respondido 27 nov., 13:15

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.