Aug-01-2020, 05:49 PM
(This post was last modified: Aug-01-2020, 06:01 PM by Axel_Erfurt.)
and better use a Class for your Main Window
and look at Pyqt5 Examples
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QProgressBar, QPushButton, QVBoxLayout, QHBoxLayout) import sys class MyWindow(QMainWindow): def __init__(self, parent=None): super(MyWindow, self).__init__() self.setGeometry(400,400,300,150) self.setWindowTitle("CodersLegacy") self.prog_bar = QProgressBar() self.prog_bar.setFixedHeight(26) self.prog_bar.setValue(0) self.button = QPushButton() self.button.setText("Update") self.button.setFixedWidth(80) self.button.clicked.connect(self.update) self.reset_button = QPushButton() self.reset_button.setText("Reset") self.reset_button.setFixedWidth(80) self.reset_button.clicked.connect(self.reset) prog_barwid = QVBoxLayout() prog_barwid.addWidget(self.prog_bar) btn_wid = QHBoxLayout() btn_wid.addWidget(self.button) btn_wid.addWidget(self.reset_button) layout = QVBoxLayout() layout.addLayout(prog_barwid) layout.addLayout(btn_wid) main_wid = QWidget() main_wid.setLayout(layout) main_wid.setFixedWidth(280) main_wid.setFixedHeight(100) self.setCentralWidget(main_wid) def update(self): self.reset() completed = 0 while completed < 100: completed += 0.0001 self.prog_bar.setValue(completed) def reset(self): value = 0 self.prog_bar.setValue(value) if __name__ == '__main__': app = QApplication(sys.argv) win = MyWindow() win.show() sys.exit(app.exec_())
and look at Pyqt5 Examples