Eli Eli - 1 month ago 7
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)