pyqt5 LCD屏幕
效果
import sys
from PyQt5.QtCore import QTimer, QTime
from PyQt5.QtWidgets import QWidget, QLCDNumber, QVBoxLayout, QApplication
class Clock(QWidget):
def __init__(self):
QWidget.__init__(self)
# set layout
self.resize(600, 300)
self.v_layout = QVBoxLayout()
self.setLayout(self.v_layout)
self.lcd = QLCDNumber()
self.lcd.setDigitCount(8)
self.v_layout.addWidget(self.lcd)
# data
self.dot = True
self.timer = QTimer(self)
self.timer.timeout.connect(self.updateTime)
self.timer.start(1000)
# update
def updateTime(self):
time = QTime.currentTime()
time_text = time.toString()
if self.dot:
time_text.replace(":", " ")
self.dot = False
else:
self.dot = True
self.lcd.display(time_text)
if __name__ == '__main__':
app = QApplication(sys.argv)
clock = Clock()
clock.show()
sys.exit(app.exec_())
comment:
- Valine
- LiveRe
- ChangYan