If your application requires getting date and/or time input from a user, this can be a difficult task due to the possible number of input formatting and validation issues. There is no need to fear, though; wxPython has several specialized controls to deal with date and time input. In this recipe, we will take a look at using DatePickerCtrl
to select dates.
Here are the steps to perform for this recipe:
Firstly, let's start by making a little wrapper class around
DatePickerCtrl
to fix a layout issue that exists on some versions of Windows, with the native control being in use:class DatePicker(wx.DatePickerCtrl): def __init__(self, parent, dt, style=wx.DP_DEFAULT): super(DatePicker, self).__init__(parent, dt=dt, style=style) self.SetInitialSize((120, -1))
Next, we will make a panel to contain the
DatePicker
control, as follows:class MyPanel(wx.Panel): def __init__(self, parent): ...