python3下pygame显示中文的设置
1.先看代码:
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()2.效果:

3.注意字体:
字体需要自己下载好,放置一个指定的文件夹
如:本游戏中的字体:
simsun.ttf
相关推荐
快递小可 2020-08-16
chuckchen 2020-10-31
Dreamhome 2020-10-09
xirongxudlut 2020-09-28
星辰大海的路上 2020-09-13
chaochao 2020-08-31
猪猪侠喜欢躲猫猫 2020-08-17
shengge0 2020-07-26
巩庆奎 2020-07-21
张文倩数据库学生 2020-07-19
xirongxudlut 2020-07-18
Ericbig 2020-07-18
kyelu 2020-07-09
liangzhouqu 2020-07-07
GuoSir 2020-06-28
chaigang 2020-06-27
pythonxuexi 2020-06-25