pygame用sysfont在display表現的小程式
pygame吧
全部回复
仅看楼主
level 6
喵喵陳 楼主
pygame用sysfont在display表現的小程式
剛開始學時我fontlist中大部份字型連0x32到0x7e都是四方框出不了字...一個一個試了由0試到27個才有1個能用的......吃透了後寫這程式竟然告訴我0x32到0x7e大部分字體都正常24號還能用中文......田字顯示不了的就是那字體沒中文,漢字字型了....
要裝了pygame才能跑!
百度网盘
---以下是源碼----
import pygame
import os
pygame.init()
win=pygame.display.get_desktop_sizes()[0]
ww=win[0]
wh=win[1]
i=1
screen = pygame.display.set_mode((ww/4*3,wh/4*3))
#pygame.FULLSCREEN )
#pygame.NOFRAME)
clock = pygame.time.Clock()
fontlist=pygame.font.get_fonts()
def fl():
th=10
tl=10
mtw=0
screen.fill((255,255,255,0))
pos=(0,0)
for i in range(len(fontlist)):
font=pygame.font.SysFont(fontlist[i],12)
s=f'{i}:{fontlist[i]}\t田'
print(s)
text=font.render(s,True,(0,0,0,128))
textRect=text.get_rect()
screen.blit(text,(tl,th))
th+=textRect.h
if(textRect.w>mtw):
mtw=textRect.w
if(th+textRect.h+10>wh/4*3):
tl+=mtw+25
th=10
mtw=0
screen.fill((255,255,255,0))
fl()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.flip()
clock.tick(60)
2024年02月04日 00点02分 1
1