import os.path import random import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QApplication, QMainWindow from MainWindow import Ui_MainWindow basedir = os.path.dirname(__file__) class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) f = self.label.font() f.setPointSize(25) self.label.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) self.label.setFont(f) self.pushButton.pressed.connect(self.update_label) def update_label(self): n = random.randint(1, 6) self.label.setText("%d" % n) app = QApplication(sys.argv) window = MainWindow() window.show() app.exec_()