你看过 wxPython 演示吗?您应该检查几个小部件。一个是模拟时钟。它真的很整洁。然后是 LEDNumberCtrl。有一个演示,它显示了实时更新的当前时间。
如果您需要显示日期,请尝试 DatePickerCtrl
更新:这是一个代码示例:
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(sizer)
dpc = wx.DatePickerCtrl(self, size=(120,-1),
style = wx.DP_DROPDOWN
| wx.DP_SHOWCENTURY
| wx.DP_ALLOWNONE )
self.Bind(wx.EVT_DATE_CHANGED, self.OnDateChanged, dpc)
sizer.Add(dpc, 0, wx.ALL, 50)
# In some cases the widget used above will be a native date
# picker, so show the generic one too.
dpc = wx.GenericDatePickerCtrl(self, size=(120,-1),
style = wx.TAB_TRAVERSAL
| wx.DP_DROPDOWN
| wx.DP_SHOWCENTURY
| wx.DP_ALLOWNONE )
self.Bind(wx.EVT_DATE_CHANGED, self.OnDateChanged, dpc)
sizer.Add(dpc, 0, wx.LEFT, 50)
def OnDateChanged(self, evt):
print "OnDateChanged: %s\n" % evt.GetDate()
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="DatePickers")
panel = MyPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()