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

2024-04-25 20:03:00 发布

您现在位置: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”拼图.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

Tags: 代码pyrectnewmaindisplaypygamesurf
1条回答
网友
1楼 · 发布于 2024-04-25 20:03:00

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

我想你的台词

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

应该是

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

相关问题 更多 >