1

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)

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?

Thank you!

falsetru
  • 357,413
  • 63
  • 732
  • 636
user3295674
  • 893
  • 5
  • 19
  • 42
  • Why do you use `QMessageBox.about(self, ...)` instead of `self.about(...)` or `profBox.about(...)` ? – falsetru Mar 03 '14 at 05:16

1 Answers1

1

Use 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 />'
falsetru
  • 357,413
  • 63
  • 732
  • 636