Skip to main content

Calendar and DateEntry widgets for Tkinter

Project description

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. tkcalendar is compatible with both Python 2 and Python 3. It support all locale settings supported by the system and the colors are customizable.

Requirements

  • Linux, Windows, Mac

  • Python 2 or 3 with tkinter + ttk (default for Windows but not for Linux)

Installation

  • Ubuntu: use the PPA ppa:j-4321-i/ppa

    $ sudo add-apt-repository ppa:j-4321-i/ppa
    $ sudo apt-get update
    $ sudo apt-get install python(3)-tkcalendar
  • Archlinux:

    The package is available on AUR

  • With pip:

$ pip install tkcalendar

Documentation

  • Calendar widget

    Syntax:

    Calendar(master=None, **kw)

    Widget keyword options:

    • Standard options

      cursor: cursor to display when the pointer is in the widget

      font: font of the calendar, can be a string such as “Arial 20 bold” or a Tkinter Font instance

      borderwidth: width of the border around the calendar (integer)

      state: normal or disabled (unresponsive widget)

    • Widget-Specific Options

      year, month: initially displayed month, default is current month

      day: initially selected day, if month or year is given but not day, no initial selection, otherwise, default is today

      locale: locale to use, e.g. “fr_FR” for a French calendar

      selectmode: “none” or “day” (default) define whether the user can change the selected day with a mouse click

      textvariable: StringVar that will contain the currently selected date as str

      background: calendar border and month/year name background color

      foreground: month/year name foreground color

      bordercolor: day border color

      background: background color of calendar border and month/year name

      foreground: foreground color of month/year name

      bordercolor: day border color

      selectbackground: background color of selected day

      selectforeground: foreground color of selected day

      disabledselectbackground: background color of selected day in disabled state

      disabledselectforeground: foreground color of selected day in disabled state

      normalbackground: background color of normal week days

      normalforeground: foreground color of normal week days

      othermonthforeground: foreground color of normal week days

      belonging to the previous/next month

      othermonthbackground: background color of normal week days

      belonging to the previous/next month

      othermonthweforeground: foreground color of week-end days

      belonging to the previous/next month

      othermonthwebackground: background color of week-end days

      belonging to the previous/next month

      weekendbackground: background color of week-end days

      weekendforeground: foreground color of week-end days

      headersbackground: background color of day names and week numbers

      headersforeground: foreground color of day names and week numbers

      disableddaybackground: background color of days in disabled state

      disableddayforeground: foreground color of days in disabled state

    • Virtual Events

      A <<CalendarSelected>> event is generated each time the user selects a day with the mouse.

  • DateEntry widget

    Date selection entry with drop-down calendar.

    Syntax:

    DateEntry(master=None, **kw)

    Widget keyword options:

    • Keyword options of Calendar to configure the drop-down calendar

    • Keyword options of ttk.Entry

      By 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 Events

      A <<DateEntrySelected>> event is generated each time the user selects a date.

Changelog

  • tkcalendar 1.2.1
    • Fix ValueError in DateEntry with Python 3.6.5

  • tkcalendar 1.2.0

    • Add textvariable option to Calendar

    • Add state (‘normal’ or ‘disabled’) option to Calendar

    • Add options disabledselectbackground, disabledselectforeground, disableddaybackground and disableddayforeground to configure colors when Calendar is disabled

    • Fix DateEntry behavior in readonly mode

    • Make Calendar.selection_get always return a datetime.date

  • tkcalendar 1.1.5

    • Fix endless triggering of <<ThemeChanged>> event in DateEntry

  • tkcalendar 1.1.4

    • Fix error in january due to week 53

    • Fix DateEntry for ttk themes other than ‘clam’

  • tkcalendar 1.1.3

    • Make DateEntry support initialisation with partial dates (e.g. just year=2010)

    • Improve handling of wrong year-month-day combinations

  • tkcalendar 1.1.2

    • Fix bug after destroying a DateEntry

    • Fix bug in style and font

  • tkcalendar 1.1.1

    • Fix bug when content of DateEntry is not a valid date

  • tkcalendar 1.1.0

    • Bug fix:

      • Fix display of the first days of the next month

      • Increment year when going from december to january

    • New widget:

      • DateEntry, date selection entry with drop-down calendar

    • New options in Calendar:

      • borderwidth: width of the border around the calendar (integer)

      • othermonthbackground: background color for normal week days belonging to the previous/next month

      • othermonthweforeground: foreground color for week-end days belonging to the previous/next month

      • othermonthwebackground: background color for week-end days belonging to the previous/next month

  • tkcalendar 1.0.0

    • Initial version

Example

try:
    import tkinter as tk
    from tkinter import ttk
except ImportError:
    import Tkinter as tk
    import ttk

from tkcalendar import Calendar, DateEntry

def example1():
    def print_sel():
        print(cal.selection_get())

    top = tk.Toplevel(root)

    cal = Calendar(top,
                   font="Arial 14", selectmode='day',
                   cursor="hand1", year=2018, month=2, day=5)
    cal.pack(fill="both", expand=True)
    ttk.Button(top, text="ok", command=print_sel).pack()

def example2():
    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)
    cal.pack(padx=10, pady=10)

root = tk.Tk()
s = ttk.Style(root)
s.theme_use('clam')

ttk.Button(root, text='Calendar', command=example1).pack(padx=10, pady=10)
ttk.Button(root, text='DateEntry', command=example2).pack(padx=10, pady=10)

root.mainloop()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tkcalendar-1.2.1.tar.gz (13.7 kB view hashes)

Uploaded Source

Built Distributions

tkcalendar-1.2.1-py3.6.egg (12.6 kB view hashes)

Uploaded Source

tkcalendar-1.2.1-py3-none-any.whl (12.8 kB view hashes)

Uploaded Python 3

tkcalendar-1.2.1-py2.7.egg (12.6 kB view hashes)

Uploaded Source

tkcalendar-1.2.1-py2-none-any.whl (12.8 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page