pyqt gui not responding
I\'m trying to make a gui for my linkedin scraper program. But the GUI bec
A GUI app is built around an event loop: Qt sits there taking events from the user, and calling your handlers. Your handlers have to return as quickly as possible, because Qt can't take the next event until you return.
That's what it means for a GUI to be "not responding": the events are just queuing up because you're not letting Qt do anything with them.
There are a few ways around this, but, with Qt in particular, the idiomatic way is to start a background thread to do the work.
You really need to read a tutorial on threading in Qt. From a quick search, this one looks decent, even though it's for PyQt4. But you can probably find a good one for PyQt5.
The short version is:
class MainBackgroundThread(QThread):
def __init__(self, keyword, sector):
QThread.__init__(self)
self.keyword, self.sector = keyword, sector
def run(self):
main(self.keyword, self.sector)
And now, your doAction
method changes to this:
def doAction(self):
self.worker = MainBackgroundThread(self.keyword.text(), self.sector.text())
self.worker.start()