0

When test_func1() or test_func2() is called, i want to increase the progressBar by the corresponding function for the number of iterations at the same time.

For example, when test_func(10) is called, the progressBar is increased every time print(i) is executed, Finally, I want to see 100% on the UI.

#======== main.py ==========#

import numpy as np
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QThread,QWaitCondition,QMutex,pyqtSignal
from Source.view.UI import main_ui
from Source.view.func import test_func1,test_func2



class Thread(QThread):
    change_value = pyqtSignal(int)

    def __init__(self):
        QThread.__init__(self)
    
    def run(self):
         ???

class VoiceWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.ui = main_ui.Ui_Dialog()
        self.ui.setupUi(self)

        self.th = Thread()
        self.prog = self.ui.progressBar
        
        self.ui.pushButton_21.clicked.connect(self._test)
        
        def _test(self):
            s_norm_yn = self.ui.radioButton_16.isChecked()
            number = self.ui.textBrowser_1.toPlainText()
            if s_norm_yn:
               test_func1(number)
            else:
               test_func2(number)
#========= func.py ==============#
def test_func1(number):
    for i in range(number):
        print(i)

def test_func2(number):
    for i in ragne(number):
        print(i+2)
mateo
  • 89
  • 4
  • Maybe you can have a look at this post : https://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt it provides examples on how to set up a worker mechanism with Thread and how to emit signals. It helped me to achieve something similar to your use case. – Beinje Jan 18 '23 at 10:53

0 Answers0