【问题标题】:pygame - invalid character in identifier [duplicate]pygame - 标识符中的无效字符[重复]
【发布时间】:2017-11-28 00:59:17
【问题描述】:

我在执行此代码时遇到上述错误。这是一个理解pygame中时钟的例子。任何建议如何消除此错误

这里是代码

import pygame, sys
from pygame.locals import *
def myquit():
    pygame.quit()
    sys.exit(0)
  
def main():
    # Initialize Pygame
    pygame.init()
  
    # Set up screen
    SCREEN_WIDTH = 600
    SCREEN_HEIGHT = 480
    window = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
    pygame.display.set_caption('Game Clock') # Set the window bar title
    screen = pygame.display.get_surface() # This is where images are displayed
  
    # Set up font
    font = pygame.font.Font(None, 36)
  
    # Set up clock
    clock = pygame.time.Clock()
    FPS = 30
    seconds = 0
    pygame.time.set_timer(USEREVENT + 1, 1000) # Used to correctly implement seconds
  
    while True: # for each frame
        clock.tick(FPS)
        screen.fill((255, 255, 255))       
        time_display = font.render("Time: " + str(clock.get_time()), 1, (0, 0, 0))
        rawtime_display = font.render("Raw Time: " + str(clock.get_rawtime()), 1, (0, 0, 0))
        fps_display = font.render("FPS: " + str(clock.get_fps()), 1, (0, 0, 0))
        pygame_total_ticks_display = font.render("Pygame Ticks (total): " + str(pygame.time.get_ticks()), 1, (0, 0, 0))
        seconds_display = font.render("Seconds: " + str(seconds), 1, (0, 0, 0))
        screen.blit(time_display, (10, 10))
        screen.blit(rawtime_display, (10, 35))
        screen.blit(fps_display, (10, 60))
        screen.blit(pygame_total_ticks_display, (10, 85))
        screen.blit(seconds_display, (10, 110))
        for event in pygame.event.get():
            if event.type == QUIT:
                quit()
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    myquit()
            elif event.type == USEREVENT + 1:
                seconds+=1
        pygame.display.flip()
  
main()
  

【问题讨论】:

  • 请勿发布代码、数据、错误消息等的图片 - 将文本复制或输入到问题中。 How to Ask

标签: python pygame


【解决方案1】:

删除并重新键入该行。您可能在其中有一些不可打印的空格,例如 zero_width_space 会弄乱名称。您可以通过从网站复制和粘贴代码来获取这些字符。

【讨论】:

    猜你喜欢
    • 2018-09-09
    • 2013-01-28
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多