{"id":9362,"library":"tkcalendar","title":"tkcalendar","description":"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.","status":"active","version":"1.6.1","language":"en","source_language":"en","source_url":"https://github.com/j4321/tkcalendar","tags":["tkinter","gui","calendar","date-picker","widget"],"install":[{"cmd":"pip install tkcalendar","lang":"bash","label":"Install stable release"}],"dependencies":[{"reason":"Used for locale settings and date pattern formatting. It is a mandatory dependency.","package":"babel"}],"imports":[{"symbol":"Calendar","correct":"from tkcalendar import Calendar"},{"symbol":"DateEntry","correct":"from tkcalendar import DateEntry"}],"quickstart":{"code":"import tkinter as tk\nfrom tkinter import ttk\nfrom tkcalendar import DateEntry\nimport datetime\n\ndef get_selected_date():\n    print(f\"Selected date: {cal.get_date()}\")\n\nroot = tk.Tk()\nroot.title(\"tkcalendar DateEntry Demo\")\n\nttk.Label(root, text=\"Select a date:\").pack(padx=10, pady=5)\n\n# Create a DateEntry widget\ncal = DateEntry(root, width=12, background='darkblue',\n                foreground='white', borderwidth=2,\n                year=datetime.date.today().year,\n                month=datetime.date.today().month,\n                day=datetime.date.today().day,\n                date_pattern='dd/MM/yyyy')\ncal.pack(padx=10, pady=10)\n\nttk.Button(root, text=\"Get Selected Date\", command=get_selected_date).pack(pady=5)\n\nroot.mainloop()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to tkcalendar v1.3.0 or newer. Ensure 'babel' is installed alongside 'tkcalendar'.","message":"Prior to v1.3.0, `tkcalendar` set the locale globally, which could cause conflicts in applications with multiple instances or other locale-dependent components. Since v1.3.0, `babel` is used for locale handling and it no longer sets the locale globally.","severity":"breaking","affected_versions":"<1.3.0"},{"fix":"If customizing the calendar cursor within `DateEntry`, use the `calendar_cursor` option instead of `cursor`.","message":"The `cursor` option for `Calendar` widget within `DateEntry` was renamed to `calendar_cursor` (around v1.5.0/v1.6.0) to prevent name clashes with the standard `ttk.Entry` cursor option.","severity":"deprecated","affected_versions":"<1.6.0"},{"fix":"Use `--hidden-import babel.numbers` with PyInstaller: `pyinstaller --hidden-import babel.numbers myscript.py` or add `hiddenimports=[\"babel.numbers\"]` to your `.spec` file.","message":"When bundling applications with PyInstaller, `tkcalendar`'s dependency on `babel.numbers` may not be detected automatically, leading to `ModuleNotFoundError` at runtime.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"In `tkcalendar` versions prior to 1.6.0, using `grab_set` could cause the `DateEntry` drop-down calendar to vanish unexpectedly upon interaction.","severity":"gotcha","affected_versions":"<1.6.0"},{"fix":"If configuring widgets using dictionaries, ensure you are on v1.5.1 or later. For older versions, pass keyword arguments directly.","message":"Since v1.5.1, `Calendar.config()` and `DateEntry.config()` methods now correctly accept a dictionary for configuration, aligning with standard Tkinter widget behavior. Prior versions might have had inconsistent behavior with dictionary-based configurations.","severity":"gotcha","affected_versions":"<1.5.1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the library: `pip install tkcalendar`. Verify the import statement: `from tkcalendar import Calendar, DateEntry`. Rename your script if it's named `tkcalendar.py`.","cause":"The `tkcalendar` library is not installed in the active Python environment, or there's a typo in the import statement, or the Python file is named `tkcalendar.py`.","error":"ModuleNotFoundError: No module named 'tkcalendar'"},{"fix":"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.","cause":"This can be caused by theme incompatibilities (especially on macOS or specific Windows themes), `grab_set` interactions, or an underlying Python issue (e.g., Python issue 38661 related to `ttk.Combobox` styling).","error":"DateEntry dropdown calendar not displaying correctly (empty, white-on-white text, or vanishes)"},{"fix":"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.","cause":"This often occurs because the `StringVar` or other internal variables used by the `DateEntry` to hold its value are local to the class's `__init__` method and get garbage-collected, severing the link to the widget.","error":"DateEntry widget inside a class does not display today's date automatically."},{"fix":"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.","cause":"Accessing internal attributes like `_date` directly is not the correct or reliable way to get the selected date. This also implies general display issues for the calendar.","error":"Calendar not showing up / DateEntry._date attribute is incorrect or not returning the selected date."}]}