1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
import sys import random from PySide2 import QtCore, QtWidgets, QtGui
class MyWidget(QtWidgets.QWidget): def __init__(self): QtWidgets.QWidget.__init__(self)
self.hello = ["Hallo Welt", "你好,世界", "Hei maailma", "Hola Mundo", "Привет мир"]
self.button = QtWidgets.QPushButton("Click me!") self.text = QtWidgets.QLabel("Hello World") self.text.setAlignment(QtCore.Qt.AlignCenter)
self.text.setFont(QtGui.QFont("Titillium", 30)) self.button.setFont(QtGui.QFont("Titillium", 20))
self.layout = QtWidgets.QVBoxLayout() self.layout.addWidget(self.text) self.layout.addWidget(self.button) self.setLayout(self.layout)
self.button.clicked.connect(self.magic)
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_())
|