简体   繁体   English

我需要帮助我如何摆脱这个?

[英]I need help how do I get rid of this?

I keep getting this error whenever I run my code:每当我运行我的代码时,我都会收到此错误:

 File "C:\Users\HOC\Desktop\Trial files\T1.py", line 50, in <module>
    screen.blit(font.render(text, True, (0, 0, 0)), (300, 180))
AttributeError: 'tuple' object has no attribute 'blit'

I'm not sure how to deal with this problem.我不知道如何处理这个问题。 This is for a game I'm making where you answer questions to move up in a race.这是我正在制作的一款游戏,您可以在其中回答问题以在比赛中晋级。 I'm planning to add buttons and options for the player to pick but I can't even get this count down to work with my button.我计划添加按钮和选项供玩家选择,但我什至无法让这个倒计时来使用我的按钮。

    import.pygame

    pygame.init()
    screen = pygame.display.set_mode((1000, 1000))
    screen = screen_width, screen_height = 1000, 1000

    def button(screen, position, text):
    font = pygame.font.SysFont("Times New Romans", 50)
    text_render = font.render(text, 1, (255, 0, 0))
    x, y, w , h = text_render.get_rect()
    x, y = position
    pygame.draw.line(screen, (150, 150, 150), (x, y), (x + w , y), 5)
    pygame.draw.line(screen, (150, 150, 150), (x, y - 2), (x, y + h), 5)
    pygame.draw.line(screen, (50, 50, 50), (x, y + h), (x + w , y + h), 5)
    pygame.draw.line(screen, (50, 50, 50), (x + w , y+h), [x + w , y], 5)
    pygame.draw.rect(screen, (100, 100, 100), (x, y, w , h))
    return screen.blit(text_render, (x, y))

    def start():
    print("Ok, let's go")

    def menu():
        b1 = button(screen, (400, 300), "Quit")
        b2 = button(screen, (500, 300), "Start")
    counter, text = 3, '3'.rjust(3)
    pygame.time.set_timer(pygame.USEREVENT, 1000)
    font = pygame.font.SysFont('Times New Romans', 30)
    run = True
    while run:
        for count in pygame.event.get():
            if count.type == pygame.USEREVENT:
                counter -= 1
            text = str(counter).rjust(3) if counter > 0 else 'GO GO GO!'
        if count.type == pygame.QUIT: 
            run = False
        for event in pygame.event.get():
            if (event.type == pygame.QUIT):
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
            if event.type == pygame.MOUSEBUTTONDOWN:
                if b1.collidepoint(pygame.mouse.get_pos()):
                    pygame.quit()
                elif b2.collidepoint(pygame.mouse.get_pos()):
                    start()
        pygame.display.update()
        pygame.quit()
        screen.blit(font.render(text, True, (0, 0, 0)), (300, 180))
        pygame.display.flip()
        clock.tick(60)
    

menu()

The problem is here:问题在这里:

screen = screen_width, screen_height = 1000, 1000

You are overwriting object of screen with tuple (1000, 1000).您正在用元组 (1000, 1000) 覆盖屏幕的 object。 Changing this line to:将此行更改为:

screen_width, screen_height = 1000, 1000

Will probably fix your problem.可能会解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM