简体   繁体   English

如何在 python 的屏幕上显示变量?

[英]How do you display variables on the screen in python?

I have looked on the web but haven't found the solution.我查看了 web 但没有找到解决方案。 Here is my code.这是我的代码。

textScore = font.render('1', True, (255, 255, 255))
text = textScore.get_rect()
text.center = (540, 50)
window.blit(textScore, text)

as you can see in the variable textScore, it is a string '1' instead of a int variable because I cant find how use a int variable in that format.正如您在变量 textScore 中看到的那样,它是一个字符串 '1' 而不是一个 int 变量,因为我找不到如何使用该格式的 int 变量。 If you can find a way around this, that would be great!如果您能找到解决此问题的方法,那就太好了!

Thanks to @Barmar, I figured out all you have to do is "convert the variable to a string, eg str(score)"感谢@Barmar,我发现您所要做的就是“将变量转换为字符串,例如str(score)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM