fork download
  1. from PyQt5.QtGui import *
  2. from PyQt5.QtWidgets import *
  3. from PyQt5.QtCore import *
  4. import time
  5.  
  6. class SomeApp(QWidget):
  7. def __init__(self):
  8. QWidget. __init__(self)
  9. self.setWindowTitle('Here we go')
  10. self.bsolve = QPushButton(self)
  11. self.bsolve.setGeometry(QRect(50,50, 40,20))
  12. self.bsolve.setText('!')
  13. self.bsolve.clicked.connect(self.myfoo)
  14. self.bsolve.setToolTip('Press X to win')
  15. self.show()
  16. def myfoo(self):
  17. self.n = 10
  18. self.cancelled = False
  19. self.progress = QProgressDialog('In use...', 'Stop!', 0, self.n, self)
  20. self.setWindowModality(Qt.WindowModal)
  21. self.progress.setMinimumDuration(1000)
  22. for self.elem in range(0, self.n):
  23. self.progress.setValue(self.elem)
  24. if self.progress.wasCanceled():
  25. self.cancelled = True
  26. return
  27. time.sleep(1)
  28. self.progress.deleteLater()
  29.  
  30. if __name__ == '__main__':
  31. import sys
  32. apl = QApplication(sys.argv)
  33. window = SomeApp()
  34. sys.exit(apl.exec_())
Runtime error #stdin #stdout #stderr 0.02s 8688KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: No module named 'PyQt5'