pygame如何实现获得并设置字体,方法是什么
Admin 2022-08-02 群英技术资讯 469 次浏览
import pygame print(pygame.font.get_fonts())
结果:
['arial', 'arialblack', 'bahnschrift', 'calibri', 'cambriacambriamath', 'cambria', 'candara', 'comicsansms', 'consolas', 'constantia', 'corbel', 'couriernew', 'ebrima', 'franklingothicmedium', 'gabriola', 'gadugi', 'georgia', 'impact', 'inkfree', 'javanesetext', 'leelawadeeui', 'leelawadeeuisemilight', 'lucidaconsole', 'lucidasans', 'malgungothic', 'malgungothicsemilight', 'microsofthimalaya', 'microsoftjhengheimicrosoftjhengheiui', 'microsoftjhengheimicrosoftjhengheiuibold', 'microsoftjhengheimicrosoftjhengheiuilight', 'microsoftnewtailue', 'microsoftphagspa', 'microsoftsansserif', 'microsofttaile', 'microsoftyaheimicrosoftyaheiui', 'microsoftyaheimicrosoftyaheiuibold', 'microsoftyaheimicrosoftyaheiuilight', 'microsoftyibaiti', 'mingliuextbpmingliuextbmingliuhkscsextb', 'mongolianbaiti', 'msgothicmsuigothicmspgothic', 'mvboli', 'myanmartext', 'nirmalaui', 'nirmalauisemilight', 'palatinolinotype', 'segoemdl2assets', 'segoeprint', 'segoescript', 'segoeui', 'segoeuiblack', 'segoeuiemoji', 'segoeuihistoric', 'segoeuisemibold', 'segoeuisemilight', 'segoeuisymbol', 'simsunnsimsun', 'simsunextb', 'sitkasmallsitkatextsitkasubheadingsitkaheadingsitkadisplaysitkabanner', 'sitkasmallsitkatextboldsitkasubheadingboldsitkaheadingboldsitkadisplayboldsitkabannerbold', 'sitkasmallsitkatextbolditalicsitkasubheadingbolditalicsitkaheadingbolditalicsitkadisplaybolditalicsitkabannerbolditalic', 'sitkasmallsitkatextitalicsitkasubheadingitalicsitkaheadingitalicsitkadisplayitalicsitkabanneritalic', 'sylfaen', 'symbol', 'tahoma', 'timesnewroman', 'trebuchetms', 'verdana', 'webdings', 'wingdings', 'yugothicyugothicuisemiboldyugothicuibold', 'yugothicyugothicuilight', 'yugothicmediumyugothicuiregular', 'yugothicregularyugothicuisemilight', 'dengxian', 'fangsong', 'kaiti', 'simhei', 'holomdl2assets', 'extra', 'opensansregular', 'opensanssemibold', '']
一般的中文字体名,使用拼音即可,如 仿宋fangsong, 楷体kaiti
新细明体:PMingLiU
细明体:MingLiU
标楷体:DFKai-SB
黑体:SimHei
宋体:SimSun
新宋体:NSimSun
仿宋:FangSong
楷体:KaiTi
仿宋_GB2312:FangSong_GB2312
楷体_GB2312:KaiTi_GB2312
微软正黑体:Microsoft JhengHei
微软雅黑体:Microsoft YaHei
import pygame,sys pygame.init()#pygame库的初始化 root_sf = pygame.display.set_mode((480,600))#创建窗口,设置大小 #显示文字 print(pygame.font.get_fonts()) font_name = pygame.font.match_font('fangsong') # 2.获得字体文件 font = pygame.font.Font(font_name, 20) # 1.获取font对象(需要字体文件) # 绘制内容:text为内容,True为是否抗锯齿, WHITE是字体颜色 font_surface = font.render('你好', True, 'white') # 3.将文字生成 surface对象 root_sf.blit(font_surface, (100, 100))#4.将文字surface对象 放到背景surface上 while True:#阻止窗口关闭 #事件判断 for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() #刷新屏幕 pygame.display.flip()
1.上方方法是匹配系统的字体
2.匹配字体文件的字体
import pygame,sys pygame.init()#pygame库的初始化 root_sf = pygame.display.set_mode((480,600))#创建窗口,设置大小 #显示文字 print(pygame.font.get_fonts()) # font_name = pygame.font.match_font('fangsong') # 2.获得字体文件 # font = pygame.font.Font(font_name, 20) # 1.获取font对象(需要字体文件) font = pygame.font.Font("simhei.ttf", 20) # 1.获取font对象(需要字体文件) # 绘制内容:text为内容,True为是否抗锯齿, WHITE是字体颜色 font_surface = font.render('你好', True, 'white') # 3.将文字生成 surface对象 root_sf.blit(font_surface, (100, 100))#4.将文字surface对象 放到背景surface上 while True:#阻止窗口关闭 #事件判断 for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() #刷新屏幕 pygame.display.flip()
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
Splinter是一个使用Python测试Web应用程序的开源工具,可以自动化浏览器操作,使用Splinter可以使用pyhton脚本来实现,具体安装及操作方法跟随小编一起看看吧
lambda 函数是一个匿名函数(即,没有名称定义),它可以接受任意数量的参数,但与普通函数不同,它只计算并返回一个表达,Python 中的 lambda 函数使用以下语法表达:
这篇文章主要为大家详细介绍了python pygame实现打砖块游戏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
所谓函数,就是把具有独立功能的代码块组织成为一个小模块,在需要的时候调用函数的使用包含两个步骤 :
这篇文章主要为大家介绍了Pytorch搭建yolo3目标检测平台实现源码,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008