|
发表于 2021-3-2 12:40:58
|
显示全部楼层
本帖最后由 洋洋痒 于 2021-3-2 13:04 编辑
- import sys
- from PyQt5.QtWidgets import QApplication, QDialog, QLabel
- class MyLabel(QLabel):
- def __init__(self,parent=None):
- super().__init__(parent)
- def timerEvent(self, *args, **kwargs):
- current_sec = int(self.text())
- current_sec -= 1
- self.setText(str(current_sec))
- class Window(QDialog):
- def __init__(self):
- super().__init__()
- self.ui()
- def ui(self):
- label = MyLabel(self)
- label.setText('10')
- label.move(100, 100)
- label.setStyleSheet('font-size:22px;')
- label.startTimer(1000)
- app = QApplication(sys.argv)
- window = Window()
- window.show()
- sys.exit(app.exec())
复制代码 |
|