【发布时间】:2020-03-31 23:57:05
【问题描述】:
import sys
from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLineEdit
class Worker(QThread):
def __init__(self, textBox):
super().__init__()
self.textBox = textBox
def run(self):
while True:
if self.textBox.text() == "close":
app.quit()
break
if self.textBox.text() == "removeFocus":
self.textBox.clearFocus()
class window(QWidget):
def __init__(self):
super().__init__()
vBox = QVBoxLayout()
self.setLayout(vBox)
self.resize(600, 400)
textBox = QLineEdit()
vBox.addWidget(textBox)
worker = Worker(textBox)
worker.start()
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = window()
sys.exit(app.exec())
当我在 textBox 中输入“close”时,它工作得很好,但当我输入“removeFocus”时,它仍然有效,但我收到此错误:
QObject::killTimer: Timers cannot be stopped from another thread
为什么即使程序正在运行,我也会收到这样的错误?
(由于我想做的过程很简单,我觉得我不能说得太多。我刚开始学习Python。这是我第一次使用这个网站。我'对不起,如果我在创建帖子时犯了错误。谢谢)
【问题讨论】:
标签: python multithreading pyqt pyqt5 qthread