python教程

事件案例演示

发布日期:2020年11月23日 07:01
阅读:6738
作者:Python GUI编程网

事件案例演示

00:00 / 01:23
1x
2x
1.5x
1.25x
1x
0.8x
0.5x

事件案例演示

from PyQt5.Qt import *
import sys

#
# class Obj(QObject):
#     def timerEvent(self, QTimerEvent):
#         print(QTimerEvent, 2)


class Label(QLabel):
    def __init__(self,*args,**kwargs):
        super().__init__(*args,**kwargs)
        self.resize(80, 40)
        self.move(100, 100)
        self.setText('10')
        self.setStyleSheet("background-color:#02CDB9;font-size:25px")

    def timerEvent(self, *args, **kwargs):
        print('事件案例演示')
        # 获取text中的数据
        sec = int(self.text())
        # 倒计时
        sec -=1
        self.setText(str(sec))
        # 停止计时
        # if sec == 0:
        #     self.killTimer(timer_id)



if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = QWidget()
    window.resize(600, 500)

    label = Label(window)

    timer_id = label.startTimer(1000)

    # label.killTimer(timer_id)

    window.show()
    sys.exit(app.exec_())