tkcalendar is a Python module that provides Calendar and DateEntry widgets for Tkinter, offering an intuitive way to select dates and display events in GUI applications. It is compatible with Python 3 and supports various locale settings and color customizations. The library is actively maintained, with its latest version being 1.6.1, and has a consistent release cadence.
pip install tkcalendarVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple Tkinter window with a DateEntry widget. It initializes the DateEntry to the current date and includes a button to retrieve the selected date, printing it to the console. The `datetime` module is often used for date manipulation.
Upgrade to tkcalendar v1.3.0 or newer. Ensure 'babel' is installed alongside 'tkcalendar'.
If customizing the calendar cursor within `DateEntry`, use the `calendar_cursor` option instead of `cursor`.
Use `--hidden-import babel.numbers` with PyInstaller: `pyinstaller --hidden-import babel.numbers myscript.py` or add `hiddenimports=["babel.numbers"]` to your `.spec` file.
Upgrade to tkcalendar v1.6.0 or newer which includes a fix for this issue. If upgrading is not possible, avoid using `grab_set` on the parent window of the DateEntry or consider temporary workarounds from community forums.
If configuring widgets using dictionaries, ensure you are on v1.5.1 or later. For older versions, pass keyword arguments directly.
Install the library: `pip install tkcalendar`. Verify the import statement: `from tkcalendar import Calendar, DateEntry`. Rename your script if it's named `tkcalendar.py`.
Update `tkcalendar` to the latest version (v1.6.0+ fixed some `grab_set` issues and Python 38661 temporary fix). Try setting a `ttk` theme like 'clam' explicitly: `style = ttk.Style(); style.theme_use('clam')`. On Windows, a temporary fix for Python issue 38661 might involve overriding `_setup_style` if using older Python/tkcalendar versions.Ensure that any `StringVar` instances or the `DateEntry` widget itself are stored as instance attributes (e.g., `self.my_date_entry = DateEntry(...)`) to prevent them from being garbage-collected prematurely.
Always use the official methods `DateEntry.get_date()` (returns `datetime.date`) or `Calendar.selection_get()` (returns `datetime.date`) to retrieve the selected date. For display issues, ensure the Tkinter mainloop is running correctly and that the widget is properly packed/gridded.