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
