如何修复代码末尾的main()?

时间:2016-01-11 02:37:44

标签: python

def main()
    global FPSCLOCK, DISPLAYSURF, BASICFONT, RESET_SURF, NEW_SURF, NEW_RECT, SOLVE_SURF, SOLVE_RECT

    pygame.init()
    FPSCLOCK = psygame.time.Clock()
    screen = psygame.display.set_mode(WINDOWWIDTH, WINDOWHEIGHT)
    pygame.display.set_caption('puzzle')
    BASICFONT = pygame.font.Font('freesansbold.ttf', BASICFONTSIZE)

代码结束:

if __name__ == '__main__':
    main()

这是我的main()代码的样子,但是当我运行我的代码(玩游戏,拼图)时,控制台会在模块>中显示File" puzzle.py",330行。我做错了什么?

命令提示符(在我启动游戏后):

Traceback (most recent call last):
  File "puzzle.py", line 330, in <module>
    main()
  File "puzzle.py", line 46, in main
    screen = pygame.display.set_mode(WINDOWWIDTH, WINDOWHEIGHT)
  TypeError: must be 2-item sequence, not int

1 个答案:

答案 0 :(得分:2)

根据Pygame's documentation,方法set_mode需要第一个参数作为元组(而不是int)。

我想你的行

screen = psygame.display.set_mode(WINDOWWIDTH, WINDOWHEIGHT))

应该是

screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))