如何更新状态栏小部件?另外我如何使用信号和线程而不是按钮?谢谢!谁能帮帮我,我的代码不起作用,当我按下按钮时没有任何反应,我也收到错误消息:
Error:
self.a = QtGui.QStatusBar.showMessage("System Status | Normal")
TypeError: QStatusBar.showMessage(QString, int msecs=0): first argument of unbound method must have type 'QStatusBar'
from PyQt4 import QtGui,QtCore
import sys
class main_window(QtGui.QWidget):
def __init__(self,parent=None):
#Layout
QtGui.QWidget.__init__(self,parent)
self.bt=QtGui.QPushButton('crash')
self.lbl=QtGui.QLabel('count')
ver=QtGui.QHBoxLayout(self)
ver.addWidget(self.bt)
self.cnt=0
self.running=False
self.connect(self.bt,QtCore.SIGNAL("clicked()"),self.count)
self.a = QtGui.QStatusBar.showMessage("System Status | Normal")
ver.addWidget(self.a)
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.count)
# check every second
self.timer.start(1000*1)
def count(self):
a = open("connection_cpu.txt","r")
if a == "CPU Overclocked":
abnormal_label = QtGui.QLabel("System Status | Normal")
abnormal_label.setStyleSheet(' QLabel {color: red}')
QtGui.QStatusBar.addWidget(abnormal_label)
self.repaint()
else:
normal_label = QtGui.QLabel("System Status | Normal")
QtGui.QStatusBar.addWidget(normal_label)
self.repaint()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mw=main_window()
mw.show()
sys.exit(app.exec_())