Eli Eli - 7 months ago 23
Python Question

Formatting text inside PYQT4?

userPassword = user_input
password = QtGui.QLabel('{}', self).format(userPassword)

I want the label to have the text inside which has been entered by the user? ERROR BELOW

AttributeError: 'QLabel' object has no attribute 'format'

Answer Source

The syntax is for the format function is str.format()

(Python Docs for str.format())

So your code should be this since you want to format the String(i.e. the '{}') and not the QLabel Object:

userPassword = user_input
password = QtGui.QLabel('{}'.format(userPassword), self)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download