0

I'm learning to use QTimer. Here is my code. I want to print "hello" every 0.5s. But it doesn't work. Where am I wrong? Thanks,

import PyQt5.QtCore

import sys
 
app = PyQt5.QtCore.QCoreApplication(sys.argv)
 
def test():

    huo = Huo()
    print('test')
    
class Huo:

    def __init__(self):
        self.timer = PyQt5.QtCore.QTimer()
        self.timer.timeout.connect(lambda: print("hello"))
        self.timer.start(500)
        
    def run(self):
        print('Huo')
 
test()

app.exec_()
ThePyGuy
  • 13,387
  • 4
  • 15
  • 42
sunynor
  • 11
  • 2

0 Answers0