from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import time
class SomeApp(QWidget):
def __init__(self):
QWidget. __init__(self)
self.setWindowTitle('Here we go')
self.bsolve = QPushButton(self)
self.bsolve.setGeometry(QRect(50,50, 40,20))
self.bsolve.setText('!')
self.bsolve.clicked.connect(self.myfoo)
self.bsolve.setToolTip('Press X to win')
self.show()
def myfoo(self):
self.n = 10
self.cancelled = False
self.progress = QProgressDialog('In use...', 'Stop!', 0, self.n, self)
self.setWindowModality(Qt.WindowModal)
self.progress.setMinimumDuration(1000)
for self.elem in range(0, self.n):
self.progress.setValue(self.elem)
if self.progress.wasCanceled():
self.cancelled = True
return
time.sleep(1)
self.progress.deleteLater()
if __name__ == '__main__':
import sys
apl = QApplication(sys.argv)
window = SomeApp()
sys.exit(apl.exec_())
ZnJvbSBQeVF0NS5RdEd1aSBpbXBvcnQgKgpmcm9tIFB5UXQ1LlF0V2lkZ2V0cyBpbXBvcnQgKgpmcm9tIFB5UXQ1LlF0Q29yZSBpbXBvcnQgKgppbXBvcnQgdGltZQoKY2xhc3MgU29tZUFwcChRV2lkZ2V0KToKICAgIGRlZiBfX2luaXRfXyhzZWxmKToKICAgICAgICBRV2lkZ2V0LiBfX2luaXRfXyhzZWxmKQogICAgICAgIHNlbGYuc2V0V2luZG93VGl0bGUoJ0hlcmUgd2UgZ28nKQogICAgICAgIHNlbGYuYnNvbHZlID0gUVB1c2hCdXR0b24oc2VsZikKICAgICAgICBzZWxmLmJzb2x2ZS5zZXRHZW9tZXRyeShRUmVjdCg1MCw1MCwgNDAsMjApKQogICAgICAgIHNlbGYuYnNvbHZlLnNldFRleHQoJyEnKQogICAgICAgIHNlbGYuYnNvbHZlLmNsaWNrZWQuY29ubmVjdChzZWxmLm15Zm9vKQogICAgICAgIHNlbGYuYnNvbHZlLnNldFRvb2xUaXAoJ1ByZXNzIFggdG8gd2luJykKICAgICAgICBzZWxmLnNob3coKQogICAgZGVmIG15Zm9vKHNlbGYpO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