计算项目。我为数学游戏制作了一个菜单,遇到了一个奇怪的错误。仅供参考我从pygame.org上删除了大部分代码。我的冒号上出现了无效的语法错误
在:
if name == 'main': main()
为什么我会收到此错误以及如何解决此问题。我以前从来没有真正编过代码,所以假设我的无知,请不要吝啬。
非常感谢:)
import pygame
nicegreen = (50, 200, 90)
black = (0, 0, 0)
def button (message, x, y, width, height, initialc, hoverc, action=None ):
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
def main():
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('Math Game Project')
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((50, 200, 90))
font = pygame.font.Font(None, 36)
text = font.render("Math Quest", 1, (120, 10, 10))
textpos = text.get_rect()
textpos.centerx = background.get_rect().centerx
background.blit(text, textpos)
# Blit everything to the screen
screen.blit(background, (0, 0))
pygame.display.flip()
# Event loop
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
startbutton(
screen.blit(background, (0, 0))
if __name__ == '__main__': main()