A Simple PySide Digital Clock

vegaseat 3 Tallied Votes 2K Views Share

PySide (public license PyQT) is my preferred Python GUI toolkit. Here we explore how to test some of the widgets available and create a digital clock.

'''ps_test_QLCDNumber_clock1.py
a simple template to test a PySide widget like QLCDNumber()
for Python33 I used the Windows self-extracting installer
PySide-1.1.2qt483.win32-py3.3.exe
from:
http://www.lfd.uci.edu/~gohlke/pythonlibs/

tested by  vegaseat  04oct12
'''

import time
from PySide.QtCore import *
from PySide.QtGui import *

app = QApplication([])  # no need to import sys

# ----- start your widget test code ----

def tick():
    # get the current local time in hh:mm:ss format
    currtime = time.strftime('%H:%M:%S')
    lcd.display(currtime)

lcd = QLCDNumber()
lcd.setDigitCount(8)

# use style sheet to set background color
# color is a string in #RRGGBB format
blue = "#0000ff"
style_str = "QWidget {background-color: %s}"
lcd.setStyleSheet(style_str % blue)

# call tick() every second to update clock display
timer = QTimer()
timer.timeout.connect(tick)
timer.start(1000)

lcd.show()

# ---- end of widget test code -----

app.exec_()
Stuart_5 0 Newbie Poster

No module named PySide.

Gribouillis 1,391 Programming Explorer Team Colleague

@Stuart_5 PySide is a third party module that needs to be installed separately. See https://pypi.python.org/pypi/PySide

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.