I recently started learning Python + PyQt5. Please help me understand how calling of class function inside another class in python.
I have the following code
from PyQt5 import QtGui, QtWidgets, QtCore, uic
from PyQt5.Qt import *
class mywindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
QtWidgets.QMainWindow.__init__(self)
self.ui = uic.loadUi('test.ui', self)
self.resize(820, 300)
self.setFixedSize(self.size())
self.pushButton.clicked.connect(self.getValue)
self.thread = {}
self.pushButtonStart.clicked.connect(self.start_worker_1)
self.pushButtonStop.clicked.connect(self.stop_worker_1)
def getValue(self):
self.value = self.spinBox.value()
i = 1
while i <= self.value:
os.system('test1.py')
i += 1
else:
print('End, i =', i)
def start_worker_1(self):
self.thread[1] = ThreadClass(parent=None, index=1)
self.thread[1].start()
self.pushButtonStart.setEnabled(False)
self.pushButtonStop.setEnabled(True)
def stop_worker_1(self):
self.thread[1].stop()
self.pushButtonStart.setEnabled(True)
self.pushButtonStop.setEnabled(False)
class ThreadClass(QtCore.QThread):
any_signal = QtCore.pyqtSignal(int)
def __init__(self, parent=None, index=0):
super(ThreadClass, self).__init__(parent)
self.index = index
self.is_running = True
def run(self):
print('Start...', self.index)
a = mywindow()
a.getValue()
def stop(self):
self.is_running = False
print('Stop...', self.index)
self.terminate()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
application = mywindow()
application.show()
sys.exit(app.exec())
I need the test.py file to be executed as many times as specified in the spinBox
Start... 1
End, i = 1
If I do while while i <= 4:
then it works. But doesn't work if I pass self.value from SpinBox.
What am I doing wrong?