【问题标题】:Make the worker thread wait for user input in GUI thread? Python/PyQt让工作线程在 GUI 线程中等待用户输入? Python/PyQt
【发布时间】: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


    【解决方案1】:

    线程之间最简单的通信方式是使用Queue 模块。让 GUI 线程 放置 一个“okay”值并让工作人员执行阻塞 get 以接收 OK 信号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-18
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      相关资源
      最近更新 更多