QMessageBox输出中的变量值?

2024-03-28 14:45:13 发布

您现在位置:Python中文网/ 问答频道 /正文

现在我在QMessageBox中显示一个包含文本的窗口。它能准确地显示文本。在

 profBox = QMessageBox()
 QMessageBox.about(self,'Profile', "Gender: <br /> Age: < br />") #Ideal output is gender: F (stored in a variable) and Age: X (also stored in a variable)

我想把某些变量的值放在性别和年龄之后,但是我对包含变量值的语法很好奇。我要先把它们转换成字符串吗?既然.about框最多只能接受三个参数,我该如何包括它们?在

谢谢你!在


Tags: in文本brselfoutputageisprofile
1条回答
网友
1楼 · 发布于 2024-03-28 14:45:13

使用^{}

>>> gender = 'M'
>>> age = 33

>>> "Gender: {}<br /> Age: {}< br />".format(gender, age)
'Gender: M<br /> Age: 33< br />'

或使用^{} operator

^{pr2}$

相关问题 更多 >