Calendar

Class

class tkcalendar.Calendar(master=None, **kw)[source]

Bases: tkinter.ttk.Frame

Calendar widget.

__init__(master=None, **kw)[source]

Construct a Calendar with parent master.

Standard Options

cursor : str
cursor to display when the pointer is in the widget
font : str or Tkinter Font instance
font of the calendar
borderwidth : int
width of the border around the calendar
state : str
“normal” or “disabled” (unresponsive widget)

Widget-specific Options

year : int
intinitially displayed year, default is current year.
month : int
initially displayed month, default is current month.
day : int
initially selected day, if month or year is given but not day, no initial selection, otherwise, default is today.
firstweekday : str
first day of the week: “monday” or “sunday”
showweeknumbers : bool
whether to display week numbers (default is True).
showothermonthdays : bool
whether to display the last days of the previous month and the first of the next month (default is True).
locale : str
locale to use, e.g. ‘en_US’
selectmode : str
“none” or “day” (default): whether the user can change the selected day with a mouse click.
textvariable : StringVar
connect the currently selected date to the variable.

Style Options

background : str
background color of calendar border and month/year name
foreground : str
foreground color of month/year name
bordercolor : str
day border color
headersbackground : str
background color of day names and week numbers
headersforeground : str
foreground color of day names and week numbers
selectbackground : str
background color of selected day
selectforeground : str
foreground color of selected day
disabledselectbackground : str
background color of selected day in disabled state
disabledselectforeground : str
foreground color of selected day in disabled state
normalbackground : str
background color of normal week days
normalforeground : str
foreground color of normal week days
weekendbackground : str
background color of week-end days
weekendforeground : str
foreground color of week-end days
othermonthforeground : str
foreground color of normal week days belonging to the previous/next month
othermonthbackground : str
background color of normal week days belonging to the previous/next month
othermonthweforeground : str
foreground color of week-end days belonging to the previous/next month
othermonthwebackground : str
background color of week-end days belonging to the previous/next month
disableddaybackground : str
background color of days in disabled state
disableddayforeground : str
foreground color of days in disabled state

Tooltip Options (for calevents)

tooltipforeground : str
tooltip text color
tooltipbackground : str
tooltip background color
tooltipalpha : float
tooltip opacity between 0 and 1
tooltipdelay : int
delay in ms before displaying the tooltip
calevent_cget(ev_id, option)[source]

Return value of given option for the event ev_id.

calevent_configure(ev_id, **kw)[source]

Configure the event ev_id.

Keyword options: date, text, tags (see calevent_create options).

calevent_create(date, text, tags=[])[source]

Add new event in calendar and return event id.

Options:

date : datetime.date or datetime.datetime instance.
event date
text : str
text to put in the tooltip associated to date.
tags : list
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)[source]

Lower event ev_id in tooltip event list.

below : str
put ev_id 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)[source]

Raise event ev_id in tooltip event list.

above : str
put ev_id above 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)[source]

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.
format_date(date=None)[source]

Convert date (datetime.date) to a string in the locale (short format).

get_calevents(date=None, tag=None)[source]

Return event ids of events with given tag and on given date.

If only date is given, return event ids of all events on date. If only tag is given, return event ids of all events with tag. If both options are None, return all event ids.

get_date()[source]

Return selected date as string.

get_displayed_month()[source]

Return the currently displayed month in the form of a (month, year) tuple.

keys()[source]

Return a list of all resource names of this widget.

selection_get()[source]

Return currently selected date (datetime.date instance). Always return None if selectmode is “none”.

selection_set(date)[source]

Set the selection to date.

date can be either a datetime.date instance or a string corresponding to the date format “%x” in the Calendar locale.

Do nothing if selectmode is “none”.

tag_cget(tag, option)[source]

Return the value of the tag’s option.

tag_config(tag, **kw)[source]

Configure tag.

Keyword options: foreground, background (of the day in the calendar)

tag_delete(tag)[source]

Delete given tag.

Delete tag properties and remove tag from all events.

tag_names()[source]

Return tuple of existing tags.

Virtual Events

  • A <<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.

Calendar Events

Special events (e.g. birthdays, ..) can be managed using the calevent_..() methods. The way they are displayed in the calendar is determined with tags. An id is attributed to each event upon creation and can be used to edit the event (ev_id argument).