gpt4 book ai didi

python - 如何输入变量并将其作为普通文本读取

转载 作者:太空宇宙 更新时间:2023-11-03 19:56:36 25 4
gpt4 key购买 nike

如何输入变量并将其作为普通文本读取?

例如

small_font = pie game.Font.System_Font('a type of font', 25)
size = 'small'
text_surface = size_font.render(text, True, color)

如何让我的计算机将大小_font.render.....读取为_font.render.. ...

摘要

我把这些放在顶部

smallfont = pygame.font.SysFont('comicsansms', 25) 
medimfont = pygame.font.SysFont('comicsansms', 50)
largefont = pygame.font.SysFont('comicsansms', 80)

我想要的是让我的计算机将 size_font.render..... 读取为small_font.render.....

最佳答案

使用您的函数作为模块的属性:

import sys

small_font = pygame.font.SysFont('comicsansms', 25)
size = 'small'
text_surface = getattr(sys.modules[__name__], "{0}_font".format(size)).render(text, True, color)

关于python - 如何输入变量并将其作为普通文本读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59500231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com