Package: tkcalendar
tkcalendar is a python module that provides the Calendar and DateEntry widgets for Tkinter.
The DateEntry widget is similar to a Combobox, but the drop-down is not a list but a Calendar to select a date.
Events can be displayed in the Calendar with custom colors and a tooltip displays the event list for a given day.
tkcalendar is compatible with both Python 2 and Python 3.
It supports many locale settings (e.g. ‘fr_FR’, ‘en_US’, ..) and the colors are customizable.The documentation is also available here:https://tkcalendar.readthedocs.ioTable of ContentsRequirementsInstallationDocumentationCalendar widgetSyntaxWidget keyword optionsVirtual EventsWidget methodsDateEntry widgetSyntaxWidget keyword optionsWidget methodsHowTosChangelogExampleRequirementsLinux, Windows, OSXPython 3And the python packages:tkinter (included in the python distribution for Windows)babelInstallationUbuntu: use the PPAppa:j-4321-i/ppa$ sudo add-apt-repository ppa:j-4321-i/ppa
$ sudo apt-get update
$ sudo apt-get install python3-tkcalendarArchlinux:The package is available onAURWith pip:$ pip install tkcalendarDocumentationCalendar widgetSyntaxCalendar(master=None, **kw)Widget keyword optionsStandard optionscursorstrcursor to display when the pointer is in the widgetfontstr such as “Arial 20 bold” or a Tkinter Font instancefont of the calendarborderwidthintwidth of the border around the calendarstatestr“normal” or “disabled” (unresponsive widget)Widget-specific options:yearintintinitially displayed year, default is current year.monthintinitially displayed month, default is current month.dayintinitially selected day, if month or year is given but not day, no initial selection, otherwise, default is today.firstweekday“monday” or “sunday”first day of the weekweekenddayslistdays to be displayed as week-end days given as a list of integers corresponding to the number of the day in the week (e.g. [6, 7] for the last two days of the week).mindatedatetime.date or datetime.datetime (default is None)minimum allowed datemaxdatedatetime.date or datetime.datetime (default is None)maximum allowed dateshowweeknumbersbool (default is True)whether to display week numbers.showothermonthdaysbool (default is True)whether to display the last days of the previous month and the first of the next month.localestrlocale to use, e.g. ‘en_US’date_patternstrdate pattern used to format the date as a string. The default pattern used
isbabel’s short date format in the calendar’s locale.A valid pattern is a combination of ‘d’, ‘m’ and ‘y’ separated by
non letter characters to indicate how and in which order the
year, month and day should be displayed.d‘d’ for the day of month number without padding, ‘dd’ for a two-digit daym‘m’ for the month number without padding, ‘mm’ for a two-digit monthy‘yy’ for the two last digits of the year, any other number of ‘y’s for
the full year with an extra padding of zero if it has less digits than
the number of ‘y’s.Examples fordatetime.date(2019, 7, 1)‘y-mm-dd’ → ‘2019-07-01’‘m/d/yy’ → ‘7/1/19’selectmode“none” or “day” (default)whether the user can change the selected day with a mouse click.textvariableStringVarconnect the currently selected date to the variable.Style options:background :background color of calendar border and month/year nameforeground :foreground color of month/year namedisabledbackgroundstrbackground color of calendar border and month/year name in disabled statedisabledforegroundstrforeground color of month/year name in disabled statebordercolor :day border colorheadersbackground :background color of day names and week numbersheadersforeground :foreground color of day names and week numbersselectbackground :background color of selected dayselectforeground :foreground color of selected daydisabledselectbackground :background color of selected day in disabled statedisabledselectforeground :foreground color of selected day in disabled statenormalbackground :background color of normal week daysnormalforeground :foreground color of normal week daysweekendbackground :background color of week-end daysweekendforeground :foreground color of week-end daysothermonthforeground :foreground color of normal week days belonging to the previous/next monthothermonthbackground :background color of normal week days belonging to the previous/next monthothermonthweforeground :foreground color of week-end days belonging to the previous/next monthothermonthwebackground :background color of week-end days belonging to the previous/next monthdisableddaybackground :background color of days in disabled statedisableddayforeground :foreground color of days in disabled stateTooltip options (for calevents):tooltipforeground :tooltip text colortooltipbackground :tooltip background colortooltipalphafloattooltip opacity between 0 and 1tooltipdelayintdelay in ms before displaying the tooltipVirtual EventsA<<CalendarSelected>>event is generated each time the user selects a day with the mouse.A<<CalendarMonthChanged>>event is generated each time the user changes the displayed month.Widget methodsStandard methods:methods common to all tkinter widgets
(more detailshere)methods common to all ttk widgets
(more detailshere)Widget-Specific methods:calevent_cget(ev_id, option) :Return value of given option for the eventev_id.calevent_configure(ev_id, **kw) :Return value of given option for the eventev_id.calevent_create(date, text, tags=[]) :Add new event in calendar and return event id.Options:date:datetime.dateordatetime.datetimeinstance.text: text to put in the tooltip associated to date.tags: list of tags to apply to the event. The last tag determines the way the event is displayed.
If there are several events on the same day, the lowest one (on the tooltip list)
which has tags determines the colors of the day.calevent_lower(ev_id, below=None) :Lower eventev_idin tooltip event list.below: put event below given one, if below is None, put it at the bottom of tooltip event list.The day’s colors are determined by the last tag of the lowest event which has tags.calevent_raise(ev_id, above=None) :Raise eventev_idin tooltip event list.above: putev_idabove given one, if above is None, put it on top of tooltip event list.The day’s colors are determined by the last tag of the lowest event which has tags.calevent_remove(*ev_ids, **kw) :Remove events from calendar.Arguments: event ids to remove or ‘all’ to remove them all.Keyword arguments:tag,date. They are taken into account only if no id is given.
Remove all events with given tag on given date. If only date is given,
remove all events on date and if only tag is given, remove all events with tag.get_date() :If selectmode is ‘day’, return the string corresponding to the selected date in theCalendarlocale, otherwise return"".get_calevents(date=None, tag=None) :Return event ids of events with given tag and on given date.If onlydateis given, return event ids of all events on date.If onlytagis given, return event ids of all events with tag.If both options are None, return all event ids.get_displayed_month() :Return the currently displayed month in the form of a (month, year) tuple.see(date) :Display the month in whichdateis.date:datetime.dateordatetime.datetimeinstance.selection_clear() :Clear the selection.selection_get() :If selectmode is ‘day’, return the selected date as adatetime.dateinstance, otherwise returnNone.selection_set(self, date) :If selectmode is ‘day’, set the selection todatewheredatecan be either adatetime.dateinstance or a string corresponding to the date format"%x"in theCalendarlocale. Does nothing if selectmode is"none".tag_cget(tag, option) :Return the value of the tag’s option.tag_config(self, tag, **kw) :Configuretag.Keyword options:foreground,background(of the day in the calendar)tag_delete(tag) :Delete given tag and remove it from all events.tag_names() :Return tuple of existing tags.DateEntry widgetDate selection entry with drop-down calendar.SyntaxDateEntry(master=None, **kw)Widget keyword optionsKeyword options ofCalendarto configure the drop-down calendarThe Calendar optioncursorhas been renamedcalendar_cursorto
avoid name clashes with the correspondingttk.Entryoption.Keyword options ofttk.EntryBy default, ‘validate’ is set to ‘focusout’ and ‘validatecommand’ is configured so that each
time the widget looses focus, if the content is not a valid date (in locale format ‘%x’),
it is reset to the previous valid date.The widget style is set to ‘DateEntry’. A custom style inheritting from ‘DateEntry’
can be created by naming it  ‘<style name>.DateEntry’Virtual EventsA<<DateEntrySelected>>event is generated each time the user selects a date.Widget methodsStandard methods:methods common to all tkinter widgets
(more detailshere)methods common to all ttk widgets
(more detailshere)methods of theEntrywidget
(more detailshere)Widget-Specific methods:drop_down() :Display or withdraw the drop-down calendar depending on its current state.get_date() :Return the selected date as adatetime.dateinstance.set_date(self, date) :Set the value of the DateEntry todatewheredatecan be either adatetime.dateinstance or a string corresponding to the date format“%x”in theCalendarlocale.HowTosWidget styling, Pyinstaller, Custom date formatting: seehttps://tkcalendar.readthedocs.io/en/stable/howtos.htmlChangelogtkcalendar 1.6.1Fix typo inDateEntrythat lead to position issues for the drop-down (#66)tkcalendar 1.6.0Fix vanishing of the drop-down calendar on any click when grab_set is usedFixDateEntrycursor customization which had no effectTemporarily fixpython issue 38661(#61)Addcalendar_cursoroption to change the cursor on theCalendarof theDateEntry(#55)Fix always on top bug using resizable (#62)tkcalendar 1.5.1Fix calendar drop-down not in front issue if window has the-topmostattribute in Windows (#49)MakeCalendar.config()andDateEntry.config()accept a dictionary like standard tkinter widgetsFix calendar not hiding when clicking again onDateEntrydrop-down button in Windows (#51)Fixmaxdatedisabled while it sould be the latest allowed date (#50)tkcalendar 1.5.0Adddisabledforegroundanddisabledbackgroundoptions to further customize
the disabled state appearance of theCalendarAddmaxdateandmindateoptions to set an allowed date range for date selectionAddweekenddaysoption to choose the days colored as week-end days (#37)Adddate_patternoption to customize the date formatAddCalendar.see()method to make sure a date is visibleMakeCalendar.selection_clear()actually clear the selectionMakelocaleoption editable after the creation of the CalendarFixValueErrorwhen retrieving default localeFix date parsing error in Swedish locale and some others (#44)Improve compliance with ttk themes by making theDateEntrylook like attk.Combobox(#42)Fix high CPU issues in Windows (#36)tkcalendar 1.4.0Add<<CalendarMonthChanged>>virtual event to theCalendarwidgetAddget_displayed_month()method to theCalendarwidgetAddshowothermonthdaysoption to show/hide the last and first days of the previous and next monthsFix display of events for January days showing on December page and converselytkcalendar 1.3.1Fix bug in day selection when firstweekday is ‘sunday’ (#28)tkcalendar 1.3.0No longer set locale globally to avoid conflicts between several instances, usebabelmodule instead (#15)Addshowwekknumbersoption to show/hide week numbers (#18)Addfirstweekdayoption to choose first week day between ‘monday’ and ‘sunday’ (#25)MakeDateEntrycompatible with more ttk themes, especially OSX default theme (#16)Add possibility to display special events (like birthdays, ..) in the calendar
The events are displayed with colors defined by tags and the event description is displayed in a tooltip
(see documentation) (#19)tkcalendar 1.2.1FixValueErrorinDateEntrywith Python 3.6.5 (#13)tkcalendar 1.2.0Addtextvariableoption toCalendar(#6)Addstate(‘normal’ or ‘disabled’) option to CalendarAdddisabledselectbackground,disabledselectforeground,disableddaybackgroundanddisableddayforegroundoptions to configure colors
whenCalendaris disabledFixDateEntrybehavior in readonly modeMakeCalendar.selection_get()always return adatetime.datetkcalendar 1.1.5Fix endless triggering of<<ThemeChanged>>event inDateEntry(#9)tkcalendar 1.1.4Fix error in January due to week 53FixDateEntryfor ttk themes other than ‘clam’ (#3)tkcalendar 1.1.3MakeDateEntrysupport initialisation with partial dates (e.g. just year=2010)Improve handling of wrong year-month-day combinationstkcalendar 1.1.2Fix bug after destroying aDateEntryFix bug in style and fonttkcalendar 1.1.1Fix bug when content ofDateEntryis not a valid datetkcalendar 1.1.0Fix display of the first days of the next monthIncrement year when going from December to JanuaryAdd widgetDateEntry: date selection entry with drop-down calendarAddborderwidth,othermonthbackground,othermonthweforeground,othermonthwebackgroundoptions to further customize the
appearance of the calendartkcalendar 1.0.0Initial versionExamplefromtkcalendarimportCalendar,DateEntrytry:importtkinterastkfromtkinterimportttkexceptImportError:importTkinterastkimportttkdefexample1():defprint_sel():print(cal.selection_get())cal.see(datetime.date(year=2016,month=2,day=5))top=tk.Toplevel(root)importdatetimetoday=datetime.date.today()mindate=datetime.date(year=2018,month=1,day=21)maxdate=today+datetime.timedelta(days=5)print(mindate,maxdate)cal=Calendar(top,font="Arial 14",selectmode='day',locale='en_US',mindate=mindate,maxdate=maxdate,disabledforeground='red',cursor="hand1",year=2018,month=2,day=5)cal.pack(fill="both",expand=True)ttk.Button(top,text="ok",command=print_sel).pack()defexample2():top=tk.Toplevel(root)cal=Calendar(top,selectmode='none')date=cal.datetime.today()+cal.timedelta(days=2)cal.calevent_create(date,'Hello World','message')cal.calevent_create(date,'Reminder 2','reminder')cal.calevent_create(date+cal.timedelta(days=-2),'Reminder 1','reminder')cal.calevent_create(date+cal.timedelta(days=3),'Message','message')cal.tag_config('reminder',background='red',foreground='yellow')cal.pack(fill="both",expand=True)ttk.Label(top,text="Hover over the events.").pack()defexample3():top=tk.Toplevel(root)ttk.Label(top,text='Choose date').pack(padx=10,pady=10)cal=DateEntry(top,width=12,background='darkblue',foreground='white',borderwidth=2,year=2010)cal.pack(padx=10,pady=10)root=tk.Tk()ttk.Button(root,text='Calendar',command=example1).pack(padx=10,pady=10)ttk.Button(root,text='Calendar with events',command=example2).pack(padx=10,pady=10)ttk.Button(root,text='DateEntry',command=example3).pack(padx=10,pady=10)root.mainloop()