Python Gui Digital Clock with PySide2 | Create Digital Clock Using Python



from PySide2.QtWidgets import QApplication, QWidget, QLCDNumber

from PySide2.QtCore import QTime, QTimer, SIGNAL
from PySide2.QtGui import QIcon
import sys

class DigitalClock(QLCDNumber):
def __init__(self, parent = None):
super(DigitalClock, self).__init__(parent)
self.setSegmentStyle(QLCDNumber.Filled)
showtime = QTimer(self)
self.connect(showtime, SIGNAL('timeout()'),self.currentTime)
showtime.start(1000) #1000ms
self.currentTime()

self.setWindowTitle("Rakshit_Coding()")
self.resize(480,400)
def currentTime(self):
curtime = QTime.currentTime()
time = curtime.toString('hh:mm')
# print(time)
# print(curtime.second())
if(curtime.second() % 2) == 0:
time = time[:2] + ' ' + time[3:]

self.display(time)

if __name__ == "__main__":
gui = QApplication(sys.argv)
window = DigitalClock()
window.show()

gui.exec_()
sys.exit(0)

output looks like...


Comments