compiled_example.py 717 B

12345678910111213141516171819202122232425262728293031323334
  1. import os.path
  2. import random
  3. import sys
  4. from PyQt5.QtCore import Qt
  5. from PyQt5.QtWidgets import QApplication, QMainWindow
  6. from MainWindow import Ui_MainWindow
  7. basedir = os.path.dirname(__file__)
  8. class MainWindow(QMainWindow, Ui_MainWindow):
  9. def __init__(self):
  10. super().__init__()
  11. self.setupUi(self)
  12. f = self.label.font()
  13. f.setPointSize(25)
  14. self.label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
  15. self.label.setFont(f)
  16. self.pushButton.pressed.connect(self.update_label)
  17. def update_label(self):
  18. n = random.randint(1, 6)
  19. self.label.setText("%d" % n)
  20. app = QApplication(sys.argv)
  21. window = MainWindow()
  22. window.show()
  23. app.exec_()