import wx
import wx.gizmos
import time
class LedClock(wx.Frame):
"""
create an LED clock showing the current time
"""
def __init__(self, parent=None):
wx.Frame.__init__(self, parent, -1, title='LED Clock',
size=(320, 100))
# default colors are green on black
self.led = wx.gizmos.LEDNumberCtrl(self, -1,
style=wx.gizmos.LED_ALIGN_CENTER)
# set up a timer
self.timer = wx.Timer(self, -1)
# update clock digits every second (1000ms)
self.timer.Start(1000)
# bind the timer to a method
self.Bind(wx.EVT_TIMER, self.update_clock)
def update_clock(self, event):
# get the current time tuple from the computer
current = time.localtime(time.time())
# time string can have characters 0..9, -, period, or space
ts = time.strftime("%H %M %S", current)
self.led.SetValue(ts)
app = wx.App(0)
LedClock().Show()
app.MainLoop()
Tidak ada komentar:
Posting Komentar