我是python编程中的新手。我正在尝试开发运行在Raspy3
上的软件。问题是,我想要一个按钮在x秒内执行一个功能(在这种情况下为10)。我试着用QTimer.singleshot,使用lambda,但冻结我的电脑和Windows控制台说是这样的: QEventDispatcherWin32::registertime: Failed to create a timer - the process has used the maximun number of handlers allowed by the system
(译自西班牙语) 下面是该程序的代码:在python上执行x秒的功能
import sys
import time
from PyQt4.QtCore import *
from PyQt4.QtCore import (QTime)
from PyQt4.QtCore import pyqtSignal as Signal
from PyQt4.QtGui import *
import ui_1
class Ventana(QMainWindow, ui_1.Ui_Ventana):
def __init__(self, parent=None):
super(Ventana, self).__init__(parent)
self.setupUi(self)
self.showMaximized()
self.botonBlanco.clicked.connect(self.blanco)
self.sliderBlanco.valueChanged.connect(self.sliderC)
self.labelBlanco.setText("Toma muestra durante 60 segundos para setear el blanco")
blancoA = False
def blanco(self):
cr = 0
while cr != 10:
QTimer.singleShot(1000, lambda: crono(cr))
def crono(self, cr):
cr += 1
return cr
def sliderC(self):
tiempoBlanco = self.sliderBlanco.value()
self.labelBlanco.setText("Toma muestra durante %i segundos para setear el blanco" % tiempoBlanco)
if __name__ == "__main__":
app = QApplication(sys.argv)
form = Ventana()
form.show()
app.exec_()
我使用Python 2.7 .11和PyQt 4 GUI 我不知道,如何解决它。任何帮助,将不胜感激。 在此先感谢
不确定这是否有帮助,但是你的lambda函数在被调用时没有返回任何变量,在'self.crono'中变量cr是私有的,并且它的任何变化都不会被'blanco'的范围 – Aaron
@Aaron +1,你是什么意思是“在'x'秒内执行一个函数”。我猜你想在单击按钮后将标签更改为1秒? –
@Aaron,这可能解释失败的原因...我会检查。 –