|
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- __author__ = 'Azir Zhang'
- #import
- #-------------------------------------------------------------------------------------------
- import time
- import wx
- import sys
- #time module
- #-------------------------------------------------------------------------------------------
- class ClockWindow(wx.Window):
- def __init__(self, parent):
- wx.Window.__init__(self, parent )
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.timer = wx.Timer(self)#创建定时器
- self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)#绑定一个定时器事件
- self.timer.Start(1000)#设定时间间隔
- self.SetBackgroundColour('black')
- def Draw(self, dc):#绘制当前时间
- t = time.localtime(time.time())
- dt = time.strftime("%m/%d/%Y %a", t)
- tt = time.strftime("%H:%M:%S",t)
- w, h = self.GetClientSize()
- dc.Clear()
- dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
- dc.SetFont(wx.Font(24, wx.ROMAN, wx.NORMAL, wx.NORMAL))
- dw, dh = dc.GetTextExtent(dt)
- tw, th = dc.GetTextExtent(tt)
- dc.SetTextForeground('white')
- dc.DrawText(dt, (w-dw)/2, (h)/3 - dh/2)
- dc.DrawText(tt, (w-tw)/2, (h)/2 - th/2)
- def OnTimer(self, evt):#显示时间事件处理函数
- dc = wx.BufferedDC(wx.ClientDC(self))
- self.Draw(dc)
- def OnPaint(self, evt):
- dc = wx.BufferedPaintDC(self)
- self.Draw(dc)
- #Weather API module
- #-------------------------------------------------------------------------------------------
- #Home module
- #-------------------------------------------------------------------------------------------
- def Start():
- print ('AQWics is waking......')
- Start()
- #Main Loop
- #-------------------------------------------------------------------------------------------
- class AQWics(wx.Frame):
- def __init__(self):
- wx.Frame.__init__(self, None, title="AQWics")
- self.SetBackgroundColour('black')
- ClockWindow(self)
- app = wx.App()
- frame = AQWics()
- frame.Show()
- app.MainLoop()
复制代码 这个代码,写的个始终的脚本,在树莓派上出现的纯白窗口。。
|
|