我的程序中有一个工作线程,它每秒都会返回一个数字,直到主窗口上的停止信号被触发。我希望它每次更改值时都发出一个信号,所以我可以用返回的值更新主窗口。我尝试在函数本身中简单地发出信号,但是不起作用。
工人:
var screen = document.getElementById("screen")
var allButtons = document.getElementsByClassName('buttons');
for (var i = 0; i < allButtons.length; i++) {
allButtons[i].addEventListener('click', pressButton)
}
function pressButton(event){
var numID = this.id; // activates ID for each button the event listener above
screen.innerHTML = numID;
};
test.py:
setNext ()
答案 0 :(得分:0)
最终代码:
from PyQt5.QtCore import QThread, QObject, pyqtSignal, pyqtSlot, Qt, QTimer
import time
class Main(QObject):
divisible_by_4 = pyqtSignal()
def __init__(self, parent=None):
QObject.__init__(self, parent=parent)
self.run = True
def main(self):
x = 1
while self.run:
print(x)
x += 1
if x%4 == 0:
self.divisible_by_4.emit()
time.sleep(1)
def stop(self):
self.run = False