Python t_箱(y+5)) pygame.draw.rect(显示我的游戏,颜色,输入框,2) pygame.display.update() 时钟滴答(60) 博弈(循环) pygame.quit() 退出 我想在用户每次输入后添加新行。而不是文本“”。我正在提

Python t_箱(y+5)) pygame.draw.rect(显示我的游戏,颜色,输入框,2) pygame.display.update() 时钟滴答(60) 博弈(循环) pygame.quit() 退出 我想在用户每次输入后添加新行。而不是文本“”。我正在提,python,pygame,pygame-surface,pygame-tick,Python,Pygame,Pygame Surface,Pygame Tick,t_箱(y+5)) pygame.draw.rect(显示我的游戏,颜色,输入框,2) pygame.display.update() 时钟滴答(60) 博弈(循环) pygame.quit() 退出 我想在用户每次输入后添加新行。而不是文本“”。我正在提供text=text+“\n”,但这不起作用。有没有更简单的方法来实现这一点?@vivs没有,你必须分别渲染每一行。 import pygame pygame.init() # game screen dimensions screen_wi

t_箱(y+5)) pygame.draw.rect(显示我的游戏,颜色,输入框,2) pygame.display.update() 时钟滴答(60) 博弈(循环) pygame.quit() 退出
我想在用户每次输入后添加新行。而不是文本“”。我正在提供text=text+“\n”,但这不起作用。有没有更简单的方法来实现这一点?@vivs没有,你必须分别渲染每一行。
import pygame
pygame.init()

# game screen dimensions
screen_width = 1200
screen_height = 800

# Define colors for using it in code
black = (0,0,0)
white = (255,255,255)
red = (255,0,0)
dark_red = (138,0,0)
green = (0,128,0)
dark_green = (0,200,0)
silver = (192,192,192)


display_mygame = pygame.display.set_mode((screen_width,screen_height))

# Primary Image
my_img = pygame.image.load('kid.png')

def game_loop():
    x = (screen_width * 0.25)
    y = (screen_height * 0.8)
    font = pygame.font.Font(None, 32)
    clock = pygame.time.Clock()
    input_box = pygame.Rect(100, 100, 240, 62)
    color_inactive = pygame.Color('lightskyblue3')
    color_active = pygame.Color('dodgerblue2')
    color = color_inactive
    active = False
    text = ''
    list = []
    count = 0
    start_width = 50
    start_height = 50
    sy = 0
    crashed = False
    while not crashed:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

            display_mygame.fill(white)
            if event.type == pygame.MOUSEBUTTONDOWN:
                if input_box.collidepoint(event.pos):
                    active = not active
                else:
                    active = False
            if event.type == pygame.KEYDOWN:
                if active:
                    if event.key == pygame.K_RETURN:
                        # Capturing the 4 instructions provided
                        list.append(str(text))
                        text = ""
                        count += 1
                        # Want the primary image to act accordingly to the instructions
                        if int(count) == 4:
                            for text in list:
                                if text == 'left':
                                    x += -300
                                elif text == 'right':
                                    x += 450
                                elif text == 'up':
                                    y += -300
                                elif text == 'down':
                                    y += 300

                    elif event.key == pygame.K_BACKSPACE:
                        text = text[:-1]
                    else:
                        text += event.unicode
        display_mygame.blit(my_img, (x,y))
        txt_surface = font.render(text, True, color)
        width = max(200, txt_surface.get_width()+10)
        input_box.w = width
        display_mygame.blit(txt_surface, (input_box.x+5, input_box.y+5))
        pygame.draw.rect(display_mygame, color, input_box, 2)

        pygame.display.update()
        clock.tick(60)

game_loop()
pygame.quit()
quit()