2011-05-28 80 views

回答

1

,你可以設置一個計時器(wx.Timer)實例產生wx.EVT_TIMER每隔几几秒/分鐘和事件負責更新與需要時的當前日期(wx.DateTime_Now())日曆結合的方法。

這裏有一個最小的工作演示代碼(嘗試更改日期:它會回到當前日期之後的第二次):

import wx 
import wx.calendar 

class MyCalendar(wx.Frame): 
    def __init__(self, *args, **kargs): 
     wx.Frame.__init__(self, *args, **kargs) 
     self.cal = wx.calendar.CalendarCtrl(self, -1, wx.DateTime_Now()) 
     self.timer = wx.Timer(self) 
     self.timer.Start(1000) 
     self.Bind(wx.EVT_TIMER, self.update_date) 

    def update_date(self, evt): 
     date = wx.DateTime_Now() 
     self.cal.SetDate(date)  

if __name__ == '__main__': 
    app = wx.PySimpleApp() 
    frame = MyCalendar(None) 
    frame.Show() 
    app.MainLoop()