Search code examples
pythondatepickerwidgetipywidgets

Choose date within a range using ipywidgets Date Picker


I need to create a widget that would allow the user to choose a date between two dates, say datetime.date(2021, 1, 1) and datetime.date(2023, 12, 31), and from the official documentation of ipywidgets I could not find anything more than this:

date_picker = widgets.DatePicker(
    description='Pick a Date',
    disabled=False,
)

Can someone please help me add constraints to the widgets? Thanks.


Solution

  • This should work:

    start_date = widgets.DatePicker(description='Start Date', disabled=False, value = datetime.date(2021,1,1))
    end_date = widgets.DatePicker(description='End Date', disabled=False, value = datetime.date(2023,12,31))