在 PYQT4 中格式化文本?

Formatting text inside PYQT4?

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

我希望标签中包含用户输入的文本?错误低于

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

格式函数的语法是 str.format()

(Python Docs for str.format())

所以你的代码应该是这样的,因为你想格式化字符串(即'{}')而不是 QLabel 对象:

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