Python 以LCD格式显示系统时钟时间
我只想用LCD格式显示系统时钟时间。我还希望使用Python 以LCD格式显示系统时钟时间,python,pyqt4,Python,Pyqt4,我只想用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
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()
QLCDNumber
具有固定数字显示(),其默认值为5
。因此,您的文本被截断为最后5个字符。您应该设置一个适当的值(在您的情况下为8)
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.lcd.setDigitCount(8) # change the number of digits displayed
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()