首頁‎ > ‎Python程式語言‎ > ‎

簡單的小時鐘

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
#author http://www.pastwind.org/ Ryan Ho
#license http://opensource.org/licenses/gpl-2.0.php GNU Public License ver. 2.0
 
#clock.py
 
import wx
 
class MyClock(wx.Frame):
def __OnTimer(self, event):
now = wx.DateTime.Format(wx.DateTime.Now(), '%H:%M:%S')
self.simpleclock.SetLabel(str(now))
 
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(250,100))
panel1 = wx.Panel(self, -1)
font = wx.Font(22, wx.DEFAULT, wx.NORMAL, wx.BOLD, 0, 'Arial')
 
box = wx.BoxSizer(wx.HORIZONTAL)
self.simpleclock = wx.StaticText(panel1, -1, wx.DateTime.Format(wx.DateTime.Now(), '%H:%M:%S'), style=wx.ALIGN_CENTER)
self.simpleclock.SetFont(font)
box.Add((-1,-1), 1)
box.Add(self.simpleclock, 0, wx.ALIGN_CENTER_VERTICAL)
box.Add((-1,-1), 1)
 
panel1.SetSizer(box)
 
self.Center()
self.Show(True)
 
self.timer = wx.Timer(self, -1)
self.Bind(wx.EVT_TIMER, self.__OnTimer, self.timer)
self.timer.Start(1000)
 
if __name__ == '__main__':
app = wx.App()
MyClock(None, -1, 'Simple Clock')
app.MainLoop()
Comments