import sys
from PyQt5.QtWidgets import QApplication, QWidget, QRadioButton,QVBoxLayout,QPushButton,QHBoxLayout, QInputDialog, QProgressBar, QLabel
from PyQt5.QtCore import QCoreApplication, QBasicTimer,Qt
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.pbar = QProgressBar(self)
self.pbar.setGeometry(50, 130, 200, 20)
lbl = QLabel('Press the vote button to submit.', self)
lbl.move(50, 170)
rbtn1 = QRadioButton('Donald rump', self)
rbtn1.move(50, 50)
rbtn1.setChecked(True)
rbtn2 = QRadioButton(self)
rbtn2.move(50, 70)
rbtn2.setText('Hamala Karris')
btn = QPushButton(self)
btn.move(100, 100)
btn.setText('&Vote')
btn.clicked.connect(lambda:MyApp.Press(self))
self.timer = QBasicTimer()
self.step = 0
vbox = QVBoxLayout()
vbox.addStretch(3)
vbox.addStretch(1)
self.showDialog()
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Voting simulator')
self.show()
def showDialog(self):
text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter your name:')
def Press(self):
self.timer.start(100, self)
# self.lbl.setText("submitting...")
# self.lbl.adjustSize()
def timerEvent(self, e):
if self.step >= 100:
self.timer.stop()
return
self.step = self.step + 1
self.pbar.setValue(self.step)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())