나도코딩_python_GUI_2) 내가 지정한 이미지로 frame 설정

728x90

2) 내가 지정한 이미지로 frame 설정할 수도 있고, 직접 색을 rgb 값을 줘서 지정할 수도 있다. 

import pygame

pygame.init() #초기화 (반드시 필요)

#화면 크기 설정 
screen_width = 480 #가로 크기 
screen_height = 640 #세로 크기 
screen = pygame.display.set_mode((screen_width, screen_height))

#화면 타이틀 설정 
pygame.display.set_caption("YongJu Game ") #게임이름 

#배경 이미지 불러오기 
background = pygame.image.load("C:\\Users\\LG\\OneDrive\\바탕 화면\\나도코딩\\pygame_basic\\background.png")

# 이벤트 루프
running = True #게임이 진행 중 ? 
while running:
    for event in pygame.event.get(): # 어떤 이벤트가 발생하였는가 ? 
        if event.type == pygame.QUIT: #창 닫히는 이벤트 발생여부
            running = False #게임 진행 중 X
    
    screen.blit(background, (0, 0)) #내가 설정한 배경 그리기 

    #screen.fill((0, 0 , 255   )) rgb 값 줘서 배경색 채울 수도 있음
    
    pygame.display.update() #pygame 은 매번 frame 다시 그려줘야 함

# pygame 종료
pygame.quit()

728x90