我只想以 LCD 格式显示系统时钟时间。我还希望使用hh:mm:ss
格式显示时间。我的代码如下。但是当我运行它时,它并不像我预期的那样。谁能解释为什么?
import sys
from PySide import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
timer = QtCore.QTimer(self)
timer.timeout.connect(self.showlcd)
timer.start(1000)
self.showlcd()
def initUI(self):
self.lcd = QtGui.QLCDNumber(self)
self.setGeometry(30, 30, 800, 600)
self.setWindowTitle('Time')
vbox = QtGui.QVBoxLayout()
vbox.addWidget(self.lcd)
self.setLayout(vbox)
self.show()
def showlcd(self):
time = QtCore.QTime.currentTime()
text = time.toString('hh:mm:ss')
self.lcd.display(text)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()