pyqt:QMessageBox输出中的变量值? [英] pyqt: Variable values in QMessageBox output?

查看:241
本文介绍了pyqt:QMessageBox输出中的变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在QMessageBox中显示一个带有文本的窗口.它可以正常工作并正确显示文本.

Right now I'm displaying a window with text in a QMessageBox. It works and displays the text accurately.

 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)

我想包括要放入Gender& amp;之后的某些变量的值.年龄,但我对包含变量值的语法感到好奇.我要先将它们转换为字符串吗?由于.about框最多只能包含三个参数,因此如何包括它们?

I would like to include the value of certain variables to put after Gender & Age but I am curious about the syntax for including variable values. Do I convert them to strings first? How do I include them since an .about box can only take a maximum of three arguments?

谢谢!

推荐答案

使用 str.format :

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

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

或使用 %运算符:

or use % operator:

>>> "Gender: %s<br /> Age: %s< br />" % (gender, age)
'Gender: M<br /> Age: 33< br />'

这篇关于pyqt:QMessageBox输出中的变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆