【发布时间】:2011-12-13 18:27:37
【问题描述】:
我有一个用 Python 编写的多线程应用程序,其中一个线程“负责” GUI,另一个是工作线程。然而,有一次,工作线程在处理数据的过程中,会发出一个带有 QString 的信号,该信号连接到 GUI 线程中的 display_image() 函数。 display_image() 函数要求用户输入一行文本。
我的问题是,如何让工作线程等待数据处理,直到 display_image() 函数返回一个值,也就是直到用户按下 OK 按钮?
GUI.py
class GUI(QMainWindow):
def __init__(self, parent=None):
super, etc
self.worker = worker.Worker()
def display_image(self, image):
"""wait for user input"""
工人.py
class Worker(QThread):
def __init__(self, parent=None):
super, etc
def run(self):
self.emit(SIGNAL("imageFound(QString)"), image)
#wait until...
self.inputted_user_text = inputted_user_text # < this is what I need to figure out
【问题讨论】:
标签: python multithreading pyqt