Python 从另一个线程PyQT正确更新重启GUI
所以我有一个进程,它有自己的线程,并将其写入(附加)到output.txt。我还有一个GUI,可以读取这个output.txt。每当Output.txt中有新内容时,我都想更新GUI。 现在我通过退出并重新执行GUI()来实现这一点。这个可以用,但看起来太满了Python 从另一个线程PyQT正确更新重启GUI,python,multithreading,qt,user-interface,pyqt4,Python,Multithreading,Qt,User Interface,Pyqt4,所以我有一个进程,它有自己的线程,并将其写入(附加)到output.txt。我还有一个GUI,可以读取这个output.txt。每当Output.txt中有新内容时,我都想更新GUI。 现在我通过退出并重新执行GUI()来实现这一点。这个可以用,但看起来太满了 class _do_scan(QtCore.QThread): trigger = QtCore.pyqtSignal() def __init__(self): QThread.__init__(sel
class _do_scan(QtCore.QThread):
trigger = QtCore.pyqtSignal()
def __init__(self):
QThread.__init__(self)
def run(self):
self.do_scan()
def do_scan():
#when found smth and written to output.txt
self.trigger.emit()
def main(options = None):
app = QtGui.QApplication(sys.argv)
scan_thread = _do_scan()
scan_thread.start()
scan_thread.trigger.connect(lambda: app.quit())
while scan_thread.isRunning():
window = Window()
window.show()
app.exec_()
window = Window()
window.show()
sys.exit(app.exec_())
你知道我怎样才能做得更好吗?
我试着用
scan_thread.trigger.connect(lambda: window.update())
scan_thread.trigger.connect(lambda: window.repaint())
但都不管用
提前谢谢