1
我試圖設置選定的日期,以便它始終是當天。我將如何去做這件事?在wx.calendar CalendarCtrl Widget上設置日期
目前如果我讓小部件坐了一天以上,所選的日期不會更新。因此日期會落後。我將如何去改變選定的日期,以便它始終保持最新?
我試圖設置選定的日期,以便它始終是當天。我將如何去做這件事?在wx.calendar CalendarCtrl Widget上設置日期
目前如果我讓小部件坐了一天以上,所選的日期不會更新。因此日期會落後。我將如何去改變選定的日期,以便它始終保持最新?
,你可以設置一個計時器(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()