Guest User

Untitled

a guest
Jan 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtCore import *
  4.  
  5.  
  6. class App(QWidget):
  7.  
  8. def __init__(self):
  9. super().__init__()
  10. self.resize(400, 200)
  11. self.edit_number = QLineEdit()
  12. self.label = QLabel('Введите число')
  13. self.button = QPushButton('нажми для начала')
  14. self.button.clicked.connect(self.clicked)
  15. layout = QVBoxLayout()
  16. layout.addWidget(self.label)
  17. layout.addWidget(self.edit_number)
  18. layout.addWidget(self.button)
  19. self.setLayout(layout)
  20.  
  21. def clicked(self):
  22. self.dialog = Dialog(self)
  23. self.dialog.exec()
  24.  
  25.  
  26. class Dialog(QDialog):
  27. def __init__(self, main):
  28. super().__init__()
  29. self.g = 1
  30. self.resize(400, 100)
  31. self.main = main
  32. self.label_dialog = QLabel()
  33. self.button_stop = QPushButton('Остановись')
  34. self.button_stop.clicked.connect(self.function_stop)
  35. layout_dialog = QVBoxLayout()
  36. layout_dialog.addWidget(self.label_dialog)
  37. layout_dialog.addWidget(self.button_stop)
  38. self.setLayout(layout_dialog)
  39. self.timer = QTimer()
  40. self.timer.timeout.connect(self.select)
  41. self.timer.start(1000)
  42.  
  43. def select(self):
  44. self.i = int(self.main.edit_number.text())
  45. if self.g <= self.i:
  46. self.label_dialog.setText(str(self.g))
  47. self.g += 1
  48.  
  49. else:
  50. self.reply = QMessageBox.information(self, 'Message', "Все сделано")
  51. if self.reply:
  52. self.timer.stop()
  53. self.main.edit_number.clear()
  54. self.close()
  55.  
  56. def function_stop(self):
  57. self.timer.stop()
  58. self.reply = QMessageBox.information(self, 'Message', "Расчет был прерван последнее "
  59. "число было равно = " + str(self.g))
  60. self.main.edit_number.clear()
  61. self.close()
  62.  
  63.  
  64. if __name__ == '__main__':
  65. app = QApplication(sys.argv)
  66. ex = App()
  67. ex.show()
  68. sys.exit(app.exec_())
Add Comment
Please, Sign In to add comment