【问题标题】:Python 3.2.1 ; Pygame 1.9.2 ; Invalid Syntax [closed]蟒蛇3.2.1; Pygame 1.9.2;无效的语法[关闭]
【发布时间】:2011-07-19 04:33:36
【问题描述】:

当我尝试运行以下程序时,收到语法错误通知:

    balli = "ball.png"
    backgroundi = "background.png"

    import pygame , sys
    from pygame.locals import *

    pygame.init()

    screen = pygame.display.set_mode((500,500) , 0 , 32)
    background = pygame.image.load(backgroundi).convert()
    cursor = pygame.image.load(balli).convert_alpha()

    while 1:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        screen.blit(background , (0,0)

        x,y = pygame.mouse.get_pos()
        x -= cursor.get_width()/2
        y -= cursor.get_height()/2

        screen.blit(cursor , (x,y))

        pygame.display.update()

问题似乎仍然存在于以“x”开头的行和“x”本身。

【问题讨论】:

  • which 到底是什么错误?完整的回溯怎么样?
  • screen.blit(background , (0,0))

标签: python syntax python-3.x pygame


【解决方案1】:

上一行缺少)

赋值只能是语句

编码愉快。

【讨论】:

  • 废话!谢谢和抱歉。我总是犯这些垃圾错误,找了半个小时,然后我的问题就浪费了互联网空间。
  • @VaryGEEK - 你应该使用一个好的 python IDE(例如 Netbeans),它可以帮助你防止这样的小错误。
【解决方案2】:

具体来说,screen.blit(background , (0,0) 应该是screen.blit(background , (0,0))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 2012-03-25
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 2010-10-27
    • 2021-08-19
    相关资源
    最近更新 更多