""" Create a Simple Qt Widgets Application """ import random import sys from PySide6 import QtCore, QtWidgets # Main Class class MyWidget(QtWidgets.QWidget): def __init__(self): super().__init__() self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир", "您好,世界!"] self.text = QtWidgets.QLabel() # 创建部件:标签 self.text.setText("Hello World") self.text.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) self.button = QtWidgets.QPushButton("Click me!") # 创建部件:按钮 self.layout = QtWidgets.QVBoxLayout(self) # 创建垂直布局 self.layout.addWidget(self.text) # 在布局中添加部件:标签 self.layout.addWidget(self.button) # 在布局中添加部件:按钮 self.button.clicked.connect(self.magic) # 将按钮的clicked信号连接到槽函数magic @QtCore.Slot() def magic(self): self.text.setText(random.choice(self.hello)) if __name__ == "__main__": app = QtWidgets.QApplication([]) widget = MyWidget() widget.resize(800, 600) widget.show() sys.exit(app.exec())
标签:__,Qt,text,self,py,QtWidgets,world,hello From: https://www.cnblogs.com/zdt168/p/18353052