본문 바로가기
파이썬

파이썬 파이 게임 : 배경색 변경 방법

by º기록 2020. 10. 25.
반응형
import pygame, sys
pygame.init()
screen = pygame.display.set_mode([800,600])
white = [255, 255, 255]
red = [255, 0, 0]
screen.fill(white)
pygame.display.set_caption("My program")
pygame.display.flip()



background = input("What color would you like?: ")
if background == "red":
    screen.fill(red)

running = True
while running:
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
        running = False
        pygame.quit()

사용자에게 원하는 배경색을 물어 보려고합니다. 사용자가 빨간색을 쓰면 색상이 변경되지 않고 여전히 흰색으로 유지됩니다.

 

해결 방법

 

다음에 디스플레이를 업데이트하면 빨간색으로 다시 그려집니다. pygame.display.update () 를 추가합니다.

background = input("What color would you like?: ")
if background == "red":
    screen.fill(red)
    pygame.display.update()

또는 (조건부로) 배경색을 변경 한 후 pygame.display.flip () 을 이동할 수 있습니다.


 

참조 페이지 https://stackoverflow.com/questions/41189928

 

 

반응형

댓글