python 중국어 인터페이스 인 스 턴 스 설정 방법

다음은 작은 편집 자 는 하나의 사례 를 통 해 사람들 로 하여 금 더욱 직관 적 이 고 명확 하 게 중국어 라 는 내용 의 조작 절 차 를 설정 해 야 한 다 는 것 을 알 게 할 것 이다.
먼저 실례 코드 를 보 여 줍 니 다:

import pygame
from pygame.locals import *
 
def main():
pygame.init()
screen = pygame.display.set_mode((1000, 450)) #     
pygame.display.set_caption('pygame          ') #    ,          
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))
 
font = pygame.font.Font(None, 60) #    ,      ,      
#font = pygame.font.Font('/home/xgj/Desktop/simsun/simsun.ttf', 60) #          ,   
text = font.render("Hello    ", 1, (10, 10, 10)) 
 
textpos = text.get_rect()
textpos.center = background.get_rect().center
background.blit(text, textpos)
screen.blit(background, (0, 0))
pygame.display.flip()
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
screen.blit(background, (0, 0))
pygame.display.flip()
if __name__ == '__main__': main()
실행 효과 표시:

메모:hello 뒤 에는 어 지 러 운 코드 입 니 다.중국어 내용 은'사랑 해'가 표시 되 지 않 았 습 니 다.
수 정 된 코드 표시:

 
import pygame
from pygame.locals import *
 
def main():
pygame.init()
screen = pygame.display.set_mode((1000, 450)) #     
pygame.display.set_caption('pygame          ') #    ,          
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((250, 250, 250))
 
#font = pygame.font.Font(None, 60) #    ,      ,      
font = pygame.font.Font('/home/xgj/Desktop/simsun/simsun.ttf', 60) #          ,   
text = font.render("Hello    ", 1, (10, 10, 10)) 
 
textpos = text.get_rect()
textpos.center = background.get_rect().center
background.blit(text, textpos)
screen.blit(background, (0, 0))
pygame.display.flip()
while 1:
for event in pygame.event.get():
if event.type == QUIT:
return
screen.blit(background, (0, 0))
pygame.display.flip()
if __name__ == '__main__': main()
실행 효과 표시:

위 에서 보 듯 이 이미 중국어 가 나 왔 다.
요약:중국어 가 포 함 된 글꼴 을 다운로드 해 야 합 니 다.예 를 들 어 simsun.ttf\#지정 한 파일 디 렉 터 리 에 두 어야 합 니 다.
python 이 중국어 인터페이스 인 스 턴 스 를 설정 하 는 방법 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.python 이 중국어 인터페이스 를 설정 하 는 방법 에 관 한 내용 은 예전 의 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 저 희 를 많이 사랑 해 주세요!

좋은 웹페이지 즐겨찾기