¾È±Ô °øºÎ¹æ

Python ÇÁ·Î±×·¡¹Ö > PyQt5 - QtCore - QTimer (ŸÀ̸Ó)

µî·ÏÀÏ : 2017-08-11 14:35 Á¶È¸¼ö : 55,544

PyQt5 ¿¡¼­ ŸÀÌ¸Ó ±â´É¿¡ ´ëÇؼ­ ¾Ë¾Æº¼·Á°í ÇÕ´Ï´Ù.

¾Æ·¡´Â ¿¹Á¦ ¼Ò½º ÀÔ´Ï´Ù.
 
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.QtCore import QTimer, QTime

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        # ¸ÞÀΠŸÀ̸Ó
        self.timer1 = QTimer(self) #ŸÀÌ¸Ó °´Ã¼ »ý¼º
        self.timer1.start(1000*1)  #1Ãʸ¶´Ù ŸÀÌ¸Ó ½ÇÇà, ½ÃÀÛ
        self.timer1.timeout.connect(self.timeout) #½½·Ô timeout() °´Ã¼ È£Ãâ

        self.timer2 = QTimer(self)
        self.timer2.start(1000*2)
        self.timer2.timeout.connect(self.timeout)


    def timeout(self):
        #ŸÀӾƿô À̺¥Æ®°¡ ¹ß»ýÇϸé È£ÃâµÇ´Â ¸Þ¼­µå
        # ¾î¶² ŸÀ̸ӿ¡ ÀÇÇؼ­ È£ÃâµÇ¾ú´ÂÁö È®ÀÎ
        sender = self.sender()

        currentTime = QTime.currentTime().toString("hh:mm:ss")

        if id(sender) == id(self.timer1):
            print("timer1 È£Ãâ -->",currentTime)
            
        if id(sender) ==id(self.timer2):
            print("timer2 È£Ãâ -->",currentTime)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWindow = MyWindow()
    sys.exit(app.exec_())
¾Æ·¡ À̹ÌÁö´Â ½ÇÇàÇÑ È­¸é ¸ð½À´Ï´Ù.

time1, time2 °¡ 1ÃÊ,2ÃÊ ´ÜÀ§·Î timeout ¸Þ¼­µå¸¦ È£ÃâÇÏ¿©, ÇöÀç ½Ã°£À» Ãâ·ÂÇØ ÁÝ´Ï´Ù.





 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.