Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] PyQt5 Full Tutorial
#4
and better use a Class for your Main Window

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
Reply


Messages In This Thread
PyQt5 Full Tutorial - by Knight18 - Aug-01-2020, 10:17 AM
RE: PyQt5 Full Tutorial - by Axel_Erfurt - Aug-01-2020, 02:46 PM
RE: PyQt5 Full Tutorial - by Knight18 - Aug-01-2020, 05:03 PM
RE: PyQt5 Full Tutorial - by Axel_Erfurt - Aug-01-2020, 05:49 PM
RE: PyQt5 Full Tutorial - by Knight18 - Aug-02-2020, 12:09 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020