需要在 运行 时间将 QLabel 文本大写
Need to capitalize the QLabel text at run-time
我正在使用 PyQT 创建一个表单,我需要在 运行-time 为 QLabel 设置文本。
我如何强制设置它始终以大写显示文本?
我正在使用 Python 进行开发。
您可以调用upper()
函数,如下所示:
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QLabel()
w.setText("word".upper())
w.show()
sys.exit(app.exec_())
或者您可以创建自定义 class
class UpperLabel(QLabel):
def __init__(self, text="", parent=None):
QLabel.__init__(self, text.upper(), parent)
def setText(self, text):
QLabel.setText(self, text.upper())
if __name__ == '__main__':
app = QApplication(sys.argv)
w = UpperLabel()
w.setText("word")
w.show()
sys.exit(app.exec_())
我正在使用 PyQT 创建一个表单,我需要在 运行-time 为 QLabel 设置文本。 我如何强制设置它始终以大写显示文本? 我正在使用 Python 进行开发。
您可以调用upper()
函数,如下所示:
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QLabel()
w.setText("word".upper())
w.show()
sys.exit(app.exec_())
或者您可以创建自定义 class
class UpperLabel(QLabel):
def __init__(self, text="", parent=None):
QLabel.__init__(self, text.upper(), parent)
def setText(self, text):
QLabel.setText(self, text.upper())
if __name__ == '__main__':
app = QApplication(sys.argv)
w = UpperLabel()
w.setText("word")
w.show()
sys.exit(app.exec_())