我正在使用PyQt4。用户点击按钮(btnReload)后,该按钮被锁定,我的应用程序从后台的服务器获取一些值。因为我不希望用户能够向该服务器发送垃圾邮件,所以用户应该能够每15秒按一次该按钮。
代码:
def btnReloadClicked(self):
self.ui.btnReload.setEnabled(False)
def timerforbutton():
threading.Timer(15.0, timerforbutton).start()
self.ui.btnReload.setEnabled(True)
#how to stop after the def timerforbutton() is runced once?
self.getTransactionData()
如何在每次执行一次后停止timerforbutton? 这是应该发生的事情: 用户点击按钮 - > btn被锁定 - > 15秒后按钮解锁。 我无法使用sleep(),因为这会冻结整个GUI。
答案 0 :(得分:0)
使用计时器和插槽或直接使用partial制作的可调用。
from functools import partial
self.ui.btnReload.setEnabled(False)
QtCore.QTimer.singleShot(15000, partial(self.ui.btnReload.setEnabled, True));