Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PyQt5.QtWidgets import *
- from PyQt5.QtCore import *
- class App(QWidget):
- def __init__(self):
- super().__init__()
- self.resize(400, 200)
- self.edit_number = QLineEdit()
- self.label = QLabel('Введите число')
- self.button = QPushButton('нажми для начала')
- self.button.clicked.connect(self.clicked)
- layout = QVBoxLayout()
- layout.addWidget(self.label)
- layout.addWidget(self.edit_number)
- layout.addWidget(self.button)
- self.setLayout(layout)
- def clicked(self):
- self.dialog = Dialog(self)
- self.dialog.exec()
- class Dialog(QDialog):
- def __init__(self, main):
- super().__init__()
- self.g = 1
- self.resize(400, 100)
- self.main = main
- self.label_dialog = QLabel()
- self.button_stop = QPushButton('Остановись')
- self.button_stop.clicked.connect(self.function_stop)
- layout_dialog = QVBoxLayout()
- layout_dialog.addWidget(self.label_dialog)
- layout_dialog.addWidget(self.button_stop)
- self.setLayout(layout_dialog)
- self.timer = QTimer()
- self.timer.timeout.connect(self.select)
- self.timer.start(1000)
- def select(self):
- self.i = int(self.main.edit_number.text())
- if self.g <= self.i:
- self.label_dialog.setText(str(self.g))
- self.g += 1
- else:
- self.reply = QMessageBox.information(self, 'Message', "Все сделано")
- if self.reply:
- self.timer.stop()
- self.main.edit_number.clear()
- self.close()
- def function_stop(self):
- self.timer.stop()
- self.reply = QMessageBox.information(self, 'Message', "Расчет был прерван последнее "
- "число было равно = " + str(self.g))
- self.main.edit_number.clear()
- self.close()
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- ex = App()
- ex.show()
- sys.exit(app.exec_())
Add Comment
Please, Sign In to add comment