广告合作
  • 今日头条

    今日头条

  • 百度一下

    百度一下,你就知道

  • 新浪网

    新浪网 - 提供新闻线索,重大新闻爆料

  • 搜狐

    搜狐

  • 豆瓣

    豆瓣

  • 百度贴吧

    百度贴吧——全球领先的中文社区

  • 首页 尚未审核订阅工具 订阅

    Python pygame font.render使用方法

    来源:网络收集  点击:  时间:2024-02-19
    【导读】:
    Python pygame中font.render使用方法工具/原料morePython3.7win7方法/步骤1/6分步阅读

    首先,要定义模块pygame,并初始化pygame.display:

    import pygame

    pygame.display.init()

    2/6

    然后,设置pygame窗口大小:

    win = pygame.display.set_mode()

    3/6

    然后,定义函数:

    def drawText(content):

    pygame.font.init()

    font = pygame.font.Font(msyhbd.ttf,58)

    选定字体及大小。

    4/6

    然后,返回text_sf参数

    text_sf = font.render(content,True,pygame.Color(0,255,0),pygame.Color(0,0,130))

    font.render参数意义:.render(内容,是否抗锯齿,字体颜色,字体背景颜色)

    5/6

    然后,调用函数drawText,并更新显示。

    win.blit(drawText( Hi ! 龙市唐川 ),(5, 190))

    pygame.display.update()

    6/6

    最后,运行:

    import pygame

    pygame.display.init()

    win = pygame.display.set_mode()

    win.fill(pygame.Color(255,255,255))

    def drawText(content):

    pygame.font.init()

    font = pygame.font.Font(msyhbd.ttf,58)

    text_sf = font.render(content,True,pygame.Color(0,255,0),pygame.Color(0,0,130))

    return text_sf

    win.blit(drawText( Hi ! 龙市唐川 ),(5, 190))

    pygame.display.update()

    显示结果如下图。

    注意事项

    tips1:图文结合查看!

    tips2:个人原创,请勿转载!

    PYTHON文字窗口PYGAME字体样式设置
    本文关键词:

    版权声明:

    1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。

    2、本站仅提供信息发布平台,不承担相关法律责任。

    3、若侵犯您的版权或隐私,请联系本站管理员删除。

    4、文章链接:http://www.1haoku.cn/art_78935.html

    相关资讯

    ©2019-2020 http://www.1haoku.cn/ 国ICP备20009186号05-06 14:52:04  耗时:0.023
    0.0229s