Hello everyone! I've found something strange on QPushButton instance. Oh, first of all, I am using..
- windows 7
- python 3.4
- PyQt5
My test code is...
# coding: utf-8
import sys, time
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.targetBtn = QPushButton('target', self)
self.targetBtn.move(100, 100)
self.targetBtn.clicked.connect(self.sleep5sec)
self.setGeometry(100, 100, 300, 300)
self.show()
def sleep5sec(self):
self.targetBtn.setEnabled(False)
time.sleep(5)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
What I want is.. when a user push the target button, the button immediately disabled. But in my code, target button is disabled after sleep(5).
What's wrong with my code?
Thank you for reading my question! Please help!