2017-11-27 5 views
0

이 코드를 실행할 때 위에서 언급 한 오류가 발생합니다. 이것은 파이 게임에서 시계를 이해하는 예입니다. 모든 제안 방법은 다음 코드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() 
   
+1

[식별자에 잘못된 문자가 있음] 가능한 복제본 (https://stackoverflow.com/questions/14844687/invalid-character-in-identifier) – abccd

답변

3

삭제가이 오류

This is the image of the error occuring in VS code

을 제거하고 유형 라인을 다시합니다. 당신은 아마도 거기에 인쇄 할 수없는 공백이 zero_width_space와 같은 이름을 지니고 있습니다. 웹 사이트에서 코드를 복사하여 붙여 넣으면 해당 문자를 얻을 수 있습니다.