python中利用pygame模块输出文字

版权声明:文章版权归作者所有,请不要随意转载抄袭,情节严重,追究法律责任!! https://blog.csdn.net/Ibelievesunshine/article/details/83041362
import pygame,sys
from pygame.locals import *
pygame.init() #初始化pygame模块
DISPLAYSURF = pygame.display.set_mode((400,300)) #长400,宽300
pygame.display.set_caption('Hello World!')
BLACK = (0,0,0)
GREEN = (0,255,0)
BLUE = (0,0,128)

fontObj = pygame.font.Font('freesansbold.ttf',32)
#render方法返回Surface对象
textSurfaceObj = fontObj.render('Hello world!',True,GREEN,BLUE)
#get_rect()方法返回rect对象
textRectObj = textSurfaceObj.get_rect()
textRectObj.center=(200,150)

while True:
	DISPLAYSURF.fill(BLACK)
	DISPLAYSURF.blit(textSurfaceObj,textRectObj)
	for event in pygame.event.get():
		if event.type==QUIT:
			pygame.quit()
			sys.exit()
	pygame.display.update()

猜你喜欢

转载自blog.csdn.net/Ibelievesunshine/article/details/83041362
今日推荐