Hal  Sauer

Hal Sauer

1591456020

Install Akaunting Self-Hosted Accounting Software on Debian 10 Buster

This tutorial will be showing you how to install Akaunting on Debian 10 Buster with Apache or Nginx web server. Akaunting is a free, open-source self-hostable accounting software. You can use it for tracking personal finance or small business accounting.

#debian #accounting software #business software #debian server #linux #self hosted

What is GEEK

Buddha Community

Install Akaunting Self-Hosted Accounting Software on Debian 10 Buster
Hal  Sauer

Hal Sauer

1591456020

Install Akaunting Self-Hosted Accounting Software on Debian 10 Buster

This tutorial will be showing you how to install Akaunting on Debian 10 Buster with Apache or Nginx web server. Akaunting is a free, open-source self-hostable accounting software. You can use it for tracking personal finance or small business accounting.

#debian #accounting software #business software #debian server #linux #self hosted

鈕 筑

鈕 筑

1679966160

用QThread 实例创建QProgressbar | PyQt5 | Python

在这个 python - PyQt5 教程中,我们将学习如何使用 QThread Real Example 创建 QProgressbar | PyQt5 | Python。进度条用于向用户指示操作的进度,并向他们保证应用程序仍在运行。

什么是 PyQt5 QProgressbar?

QProgressBar小部件由逐渐填充的水平或垂直条组成,以指示任务的进度。它通常用于涉及耗时操作的应用程序,例如文件上传或下载、软件安装或任何其他可能需要一段时间才能完成的过程。

QProgressBar 小部件可以被定制以显示不同的颜色、字体和大小。它还提供了各种属性和方法,允许开发人员控制其行为,例如最小值和最大值、当前值以及条形图的方向。

总的来说,QProgressBar 小部件是一个有用的工具,可以向用户提供有关任务进度的视觉反馈,并且可以帮助使应用程序更加用户友好和直观。

例如,这些是我们需要的导入


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time

这是我们的线程类,这个类从QThread 扩展而来,一个 QThread 对象在程序中管理一个线程控制。QThreads 在 run() 中开始执行。默认情况下,run() 通过调用 exec() 启动事件循环,并在线程内运行 Qt 事件循环。


class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)

在我们创建了从 QDialog 扩展的 Window 类之后,我们在该类中添加了我们的窗口的要求,如标题、几何图形和带有 QProgresBar 的图标以及 QPushButton 我们还为我们的进度条使用了一些风格和设计。

class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()

这些是我们将用于启动和设置 QProgressBar 值的方法。


  def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)

此外,每个 PyQt5 应用程序都必须创建一个应用程序对象。 

App = QApplication(sys.argv)

最后,我们进入应用程序的主循环。事件处理从这一点开始。 

window = Window()
sys.exit(App.exec_())

带有 QThread 的 QProgressbar 的完整源代码


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time
 
 
class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)
class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::
        # chunk {background:
        # qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()
 
    def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)
 
 
 
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())

这将是 PyQt5 QProgressBar 代码的结果。

PyQt5 QProgressbar With QThread 实例

PyQt5 QProgressbar With QThread 实例

您也可以观看 PyQt5 QProgressbar With QThread Practical Example 的完整视频。

文章来源:https: //codeloop.org

#python #pyqt5 

Duy  Tien

Duy Tien

1679720773

Tạo QProgressbar với QThread Ví dụ thực tế | PyQt5 | Python

Trong hướng dẫn python - PyQt5 này, chúng ta sẽ tìm hiểu về Cách tạo QProgressbar bằng QThread Ví dụ thực tế | PyQt5 | con trăn. Thanh tiến trình được sử dụng để cung cấp cho người dùng chỉ báo về tiến trình của một thao tác và để đảm bảo với họ rằng ứng dụng vẫn đang chạy.

PyQt5 QProgressbar là gì?

Tiện ích QProgressBar bao gồm thanh ngang hoặc dọc lấp đầy dần dần để cho biết tiến trình của một tác vụ. nó thường được sử dụng trong các ứng dụng liên quan đến các thao tác tốn thời gian, chẳng hạn như tải lên hoặc tải xuống tệp, cài đặt phần mềm hoặc bất kỳ quy trình nào khác có thể mất một lúc để hoàn thành.

Tiện ích QProgressBar có thể được tùy chỉnh để hiển thị các màu, phông chữ và kích cỡ khác nhau. Nó cũng cung cấp các thuộc tính và phương thức khác nhau cho phép các nhà phát triển kiểm soát hành vi của nó, chẳng hạn như giá trị tối thiểu và tối đa, giá trị hiện tại và hướng của thanh.

Nhìn chung, tiện ích QProgressBar là một công cụ hữu ích để cung cấp phản hồi trực quan cho người dùng về tiến độ của một tác vụ và có thể giúp làm cho ứng dụng trở nên thân thiện và trực quan hơn với người dùng.

Đây là những hàng nhập khẩu mà chúng ta cần chẳng hạn


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time

Đây là lớp luồng của chúng tôi và lớp này mở rộng từ QThread, một đối tượng QThread quản lý một luồng điều khiển trong chương trình. QThreads bắt đầu thực thi trong run(). Theo mặc định, run() bắt đầu vòng lặp sự kiện bằng cách gọi hàm exec() và chạy vòng lặp sự kiện Qt bên trong luồng.


class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)

Sau khi chúng tôi tạo lớp Cửa sổ mở rộng từ QDialog và trong lớp đó, chúng tôi thêm các yêu cầu của cửa sổ như tiêu đề, hình học và biểu tượng bằng QProgresBar và cả QPushButton . chúng tôi cũng đã sử dụng một số phong cách và thiết kế cho thanh tiến trình của mình.

class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()

Đây là những phương pháp mà chúng ta sẽ sử dụng để bắt đầu và thiết lập giá trị của QProgressBar.


  def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)

Ngoài ra, mọi ứng dụng PyQt5 phải tạo một đối tượng ứng dụng. 

App = QApplication(sys.argv)

Cuối cùng, chúng tôi vào vòng lặp chính của ứng dụng. Việc xử lý sự kiện bắt đầu từ thời điểm này. 

window = Window()
sys.exit(App.exec_())

Hoàn thành mã nguồn cho QProgressbar với QThread


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time
 
 
class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)
class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::
        # chunk {background:
        # qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()
 
    def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)
 
 
 
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())

Đây sẽ là kết quả của mã cho PyQt5 QProgressBar.

PyQt5 QProgressbar với QThread Ví dụ thực tế

PyQt5 QProgressbar với QThread Ví dụ thực tế

Ngoài ra, bạn có thể xem video hoàn chỉnh cho PyQt5 QProgressbar Với Ví dụ thực tế về QThread.

nguồn bài viết tại: https://codeloop.org

#python  #pyqt5 

Criar QProgressbar com QThread Exemplo Real | PyQt5 | Python

Neste tutorial python - PyQt5 aprenderemos como criar uma QProgressbar usando QThread Real Example | PyQt5 | Python. Uma barra de progresso é usada para dar ao usuário uma indicação do progresso de uma operação e para assegurar que o aplicativo ainda está em execução.

O que é PyQt5 QProgressbar?

O widget QProgressBar consiste em uma barra horizontal ou vertical que é preenchida gradualmente para indicar o andamento de uma tarefa. é frequentemente usado em aplicativos que envolvem operações demoradas, como uploads ou downloads de arquivos, instalações de software ou qualquer outro processo que pode demorar um pouco para ser concluído.

O widget QProgressBar pode ser personalizado para exibir diferentes cores, fontes e tamanhos. Ele também fornece várias propriedades e métodos que permitem aos desenvolvedores controlar seu comportamento, como os valores mínimo e máximo, o valor atual e a orientação da barra.

No geral, o widget QProgressBar é uma ferramenta útil para fornecer feedback visual aos usuários sobre o andamento de uma tarefa e pode ajudar a tornar os aplicativos mais fáceis de usar e intuitivos.

Estas são as importações que precisamos, por exemplo


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time

Esta é nossa classe de encadeamento e esta classe se estende de QThread, um objeto QThread gerencia um encadeamento de controle dentro do programa. QThreads começam a executar em run(). Por padrão, run() inicia o loop de evento chamando exec() e executa um loop de evento Qt dentro do thread.


class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)

Depois criamos nossa classe Window que estende de QDialog e nessa classe adicionamos os requisitos de nossa janela como título, geometria e ícone com QProgresBar e também um QPushButton. também usamos algum estilo e design para nossa barra de progresso.

class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()

Esses são os métodos que usaremos para iniciar e definir o valor de QProgressBar.


  def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)

Além disso, todo aplicativo PyQt5 deve criar um objeto de aplicativo. 

App = QApplication(sys.argv)

Por fim, entramos no mainloop da aplicação. A manipulação do evento começa a partir deste ponto. 

window = Window()
sys.exit(App.exec_())

Código-fonte completo para QProgressbar com QThread


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time
 
 
class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)
class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::
        # chunk {background:
        # qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()
 
    def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)
 
 
 
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())

Este será o resultado do código para o PyQt5 QProgressBar.

PyQt5 QProgressbar com QThread Exemplo prático

PyQt5 QProgressbar com QThread Exemplo prático

Além disso, você pode assistir ao vídeo completo do exemplo prático PyQt5 QProgressbar com QThread.

fonte do artigo em: https://codeloop.org

#python  #pyqt5 

Wasswa  Meagan

Wasswa Meagan

1679657598

Create QProgressbar with QThread Real Example | PyQt5 | Python

In this python - PyQt5 tutorial we will learn about How to create a QProgressbar using QThread Real Example | PyQt5 | Python. A progress bar is used to give the user an indication of the progress of an operation and to reassure them that the application is still running.

What is PyQt5 QProgressbar ?

QProgressBar widget consists of horizontal or vertical bar that fills up gradually to indicate the progress of a task. it is often used in applications that involve time consuming operations, such as file uploads or downloads, software installations or any other process that may take a while to complete.

QProgressBar widget can be customized to display different colors, fonts, and sizes. It also provides various properties and methods that allow developers to control its behavior, such as the minimum and maximum values, the current value, and the orientation of the bar.

Overall, the QProgressBar widget is a useful tool for providing visual feedback to users on the progress of a task and can help make applications more user-friendly and intuitive.

These are the imports that we need for example


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time

This is our thread class and this class extends from QThread, a QThread object manages one thread of control within the program. QThreads begin executing in run(). By default, run() starts the event loop by calling exec() and runs a Qt event loop inside the thread.


class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)

After we create our Window class that extends from QDialog and in that class we add the requirements of our window like title, geometry and icon with QProgresBar and also a QPushButton. also we have used some style and design for our progressbar.

class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::chunk {background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()

These are the methods that we are going to use for starting and setting the value of the QProgressBar.


  def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)

Also every PyQt5 application must create an application object. 

App = QApplication(sys.argv)

Finally, we enter the mainloop of the application. The event handling starts from this point. 

window = Window()
sys.exit(App.exec_())

Complete source code for QProgressbar with QThread


from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton, QVBoxLayout
import sys
from PyQt5.QtCore import Qt, QThread, pyqtSignal
import time
 
 
class MyThread(QThread):
    # Create a counter thread
    change_value = pyqtSignal(int)
    def run(self):
        cnt = 0
        while cnt < 100:
            cnt+=1
            time.sleep(0.3)
            self.change_value.emit(cnt)
class Window(QDialog):
    def __init__(self):
        super().__init__()
        self.title = "PyQt5 ProgressBar"
        self.top = 200
        self.left = 500
        self.width = 300
        self.height = 100
        self.setWindowIcon(QtGui.QIcon("icon.png"))
        self.setWindowTitle(self.title)
        self.setGeometry(self.left, self.top, self.width, self.height)
        vbox = QVBoxLayout()
        self.progressbar = QProgressBar()
        #self.progressbar.setOrientation(Qt.Vertical)
        self.progressbar.setMaximum(100)
        self.progressbar.setStyleSheet("QProgressBar {border: 2px solid grey;border-radius:8px;padding:1px}"
                                       "QProgressBar::chunk {background:yellow}")
        #qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white);
        #self.progressbar.setStyleSheet("QProgressBar::
        # chunk {background:
        # qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 red, stop: 1 white); }")
        #self.progressbar.setTextVisible(False)
        vbox.addWidget(self.progressbar)
        self.button = QPushButton("Start Progressbar")
        self.button.clicked.connect(self.startProgressBar)
        self.button.setStyleSheet('background-color:yellow')
        vbox.addWidget(self.button)
        self.setLayout(vbox)
        self.show()
 
    def startProgressBar(self):
        self.thread = MyThread()
        self.thread.change_value.connect(self.setProgressVal)
        self.thread.start()
 
    def setProgressVal(self, val):
        self.progressbar.setValue(val)
 
 
 
App = QApplication(sys.argv)
window = Window()
sys.exit(App.exec_())

This will be the result of the code for the PyQt5 QProgressBar.

PyQt5 QProgressbar With QThread Practical Example

PyQt5 QProgressbar With QThread Practical Example

Also you can watch the complete video for PyQt5 QProgressbar With QThread Practical Example.

article source at: https://codeloop.org

#python #pyqt5