Nov-29-2018, 02:14 PM
Hey All
I m trying to update a textbox with signals from a thread. But I am unable to wrap my head around the business of signals.
Here is what I have so far:
Main function
ThreadSignal.py
I m trying to update a textbox with signals from a thread. But I am unable to wrap my head around the business of signals.
Here is what I have so far:
Main function
ThreadSignal.py
from PyQt5.QtWidgets import QApplication, QDialog from PyQt5.QtCore import pyqtSignal from ThreadSignalUI import Ui_MainWindow from threading import Thread import sys import time class WorkThread(Thread): def __init__(self): Thread.__init__(self) self.stop_work_thread = 0 self.start() self.val = 0 def run(self): runningval = 0 UpdateTextBoxSignal = pyqtSignal() while runningval < 10: runningval += 1 self.UpdateTextBoxSignal.emit(runningval) time.sleep(0.5) class ThreadSignal(Ui_MainWindow): def __init__(self, Application): Ui_MainWindow.__init__(self) self.setupUi(Application) self.StartButt.clicked.connect(self.StartThreading) def StartThreading(self, event): self.work = WorkThread() self.UpdateTextBoxSignal.connect(UpdateTextBoxFunction) def UpdateTextBoxFunction(self): self.TextBox.setText(str(runningval)) app = 0 app = QApplication(sys.argv) Application = QDialog() Program = ThreadSignal(Application) Application.show() app.exec_()ThreadSignalUI.py
from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(269, 232) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.TextBox = QtWidgets.QLineEdit(self.centralwidget) self.TextBox.setGeometry(QtCore.QRect(74, 40, 113, 20)) self.TextBox.setObjectName("TextBox") self.StartButt = QtWidgets.QPushButton(self.centralwidget) self.StartButt.setGeometry(QtCore.QRect(94, 72, 75, 23)) self.StartButt.setObjectName("StartButt") self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) self.StartButt.setText(_translate("MainWindow", "Start"))I followed a couple of tutorials to get to this point, but still unable to get a working program.