0

What I am trying to accomplish: Change the value of the progressbars on my GUI that is running on a thread. This value would be calculated outside the thread.

My question: How can I call the function defined under the class of the UI from my main? When I try to call it through Ui.updateProgressBar() I get updateProgressBar() missing 1 required positional argument: 'self'

This is my code:

import PyQt5.QtWidgets
from PyQt5 import QtWidgets, uic
import pbl3_rc
import sys
import threading

class Ui(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui, self).__init__()__init__
        uic.loadUi('PBL3_designer.ui', self)
        self.prog_bar_cinza1 = self.findChild(PyQt5.QtWidgets.QProgressBar, 'progbar_set_cinza1')
        self.prog_bar_cinza2 = self.findChild(PyQt5.QtWidgets.QProgressBar, 'progbar_set_cinza2')
        self.prog_bar_cores1 = self.findChild(PyQt5.QtWidgets.QProgressBar, 'progbar_set_cores1')
        self.updateProgressBar()
        self.show()

    def updateProgressBar(self):
        self.prog_bar_cinza1.setValue(val)
        self.prog_bar_cinza2.setValue(val*2)
        self.prog_bar_cores1.setValue(val*3)


def interface():
    app = QtWidgets.QApplication(sys.argv)
    ex = Ui()
    app.exec_()


for i in range(5):
    val += 1
    print(val)

t = threading.Thread(target=interface)
t.daemon = True
t.start()

for i in range(5):
    val += 1
    print(val)

Ui.updateProgressBar()
RoboNewb
  • 1
  • 1
  • If you're expecting help, your code should be a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). It should be something we can copy and paste into our code editor and run straight away. I won't lie: it can be time consuming to craft an example that illustrates your problem. But you are more likely to get high quality answers with a high quality question. – bfris Feb 06 '22 at 18:01
  • When using PyQt5, it's best to use QThreads instead of Python threads. Check out [this question](https://stackoverflow.com/q/52993677/9705687). – bfris Feb 06 '22 at 18:05
  • Ty for your input, I will read the material – RoboNewb Feb 06 '22 at 18:16
  • The QApplication must be run in the main thread, and also all UI elements (widgets, which are not thread safe) can only exist and be modified there. – musicamante Feb 06 '22 at 19:20

0 Answers0