[Solved]To display system clock time in LCD format
-
To display system clock time in LCD format
I just want to display system clock time in LCD format, also want the time to be displayed with the format of hh:mm:ss ,my code is as following ,but when I run it ,it is out of my expectaions ,so anyone can explain why ?@import sys
from PyQt4 import QtGui, QtCoreclass 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()
@ -
[quote author="redstoneleo" date="1349317955"]want the time to be displayed with the format of hh:mm:ss
...
@text = time.toString('hh:mm')@
[/quote]You want hh:mm:ss, but you wrote hh:mm. Is that the cause? If not, please describe what happens when you run your program, and why "it is out of my expectaions". -
[quote author="JKSH" date="1349318198"][quote author="redstoneleo" date="1349317955"]want the time to be displayed with the format of hh:mm:ss ... @text = time.toString('hh:mm')@ [/quote]You want hh:mm:ss, but you wrote hh:mm. Is that the cause? If not, please describe what happens when you run your program, and why "it is out of my expectaions". [/quote]
text = time.toString('hh:mm:ss')
doesn't work ? why?
-
-Hmm, I just realized, QLCDNumber can only display numbers. It can't display ":"-
Edit: Sorry, yes it can: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qlcdnumber.html
But, you need to describe what you see. Otherwise, I can't guess what's wrong.
-
You need to set the digit count on the LCD to have enough room for all 8 characters of the system time "hh:mm:ss". The default digit count is 5, thus why you are only seeing "mm:ss". I did something very similar a while back as follows:
@
from PyQt4.QtGui import QApplication, QWidget, QVBoxLayout, QLCDNumber
from PyQt4.QtCore import QTimeclass SystemClock(QWidget):
def init(self, parent=None):
QWidget.init(self, parent)self.setWindowTitle("System Clock") self.resize(640,240) l=QVBoxLayout(self) self.lcd=QLCDNumber(self, digitCount=8) l.addWidget(self.lcd) self.startTimer(1000) def timerEvent(self, e): self.lcd.display(QTime.currentTime().toString("hh:mm:ss"))
if name=="main":
from sys import argv, exit
a=QApplication(argv)
s=SystemClock()
s.show()
exit(a.exec_())
@ -
thanks all your replies ,now it worked in jazzycamel 's way .thanks!!!