python Solutions when you find that QTimer is not available
- 2021-06-29 11:40:40
- OfStack
As follows:
# -*- coding: utf-8 -*-
import numpy as np
from PyQt5.QtCore import QTimer, QObject
from PyQt5.QtWidgets import QWidget, QApplication
import sys
import time
class my_timer(QWidget):
def __init__(self):
super(my_timer, self).__init__()
self.my_t = QTimer(self)
# self.my_t.setInterval(1000)
self.my_t.start(1000)
self.my_t.timeout.connect(self.my_function)
def my_function(self):
for i in range(10):
print('_(%s)' % str(i))
time.sleep(0.5)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = my_timer()
w.show()
sys.exit(app.exec_())
When you find that QTimer has no effect, please give QTimer to the interface. When you write QTimer to the interface, you will find that QTimer is working.