import sys
from PyQt5.QtWidgets import QWidget, QLabel, QApplication,QLCDNumber, QVBoxLayout
from PyQt5.QtCore import (QCoreApplication, QObject, QRunnable, QThread, QThreadPool, pyqtSignal)
from PyQt5 import QtGui
import time
class Scoreboard(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
scoreLcd = QLCDNumber(self)
scoreLcd.display(x) #How to grab values in x below to display here
self.setGeometry(10, 50, 100, 100)
self.setWindowTitle('TIMER')
self.show()
class CountUp(QThread):
def run(self):
x = 0
while 1:
x = x + 1
time.sleep(1)
print (x) #I want the value in x to be printed in the GUI above
def Counter():
app = QApplication(sys.argv)
ex = Scoreboard()
thread = CountUp()
thread.finished.connect(app.exit)
thread.start()
sys.exit(app.exec_())
if __name__ == '__main__':
Counter()
我有两个不同的类CountUp运行while循环和Scoreboard显示数字。现在我试图将Count中的值从CountUp类打印到Scoreboard类中:
scoreLcd.display(x)
给出了一个错误,即x未定义。这是因为我试图从另一个类中获取值。
所以现在问题是如何从类记分板
访问x的值