Python pyqt:QMessageBox输出中的变量值?
现在,我正在QMessageBox中显示一个包含文本的窗口。它可以准确地工作并显示文本Python pyqt:QMessageBox输出中的变量值?,python,string,qmessagebox,Python,String,Qmessagebox,现在,我正在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) profBox=QMess
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)
profBox=QMessageBox()
QMessageBox.about(self,'Profile',“性别:
年龄:
”)理想的输出是性别:F(存储在变量中)和年龄:X(也存储在变量中)
我想在性别和年龄之后包含某些变量的值,但我对包含变量值的语法很好奇。我要先把它们转换成字符串吗?由于.about框最多只能接受三个参数,如何包含它们
谢谢大家! 使用:
为什么要使用
QMessageBox.about(self)
而不是self.about(…)
或profBox.about(…)
?
>>> gender = 'M'
>>> age = 33
>>> "Gender: {}<br /> Age: {}< br />".format(gender, age)
'Gender: M<br /> Age: 33< br />'
>>> "Gender: %s<br /> Age: %s< br />" % (gender, age)
'Gender: M<br /> Age: 33< br />'