tkcalendar

1.6.1 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import tkinter as tk
from tkinter import ttk
from tkcalendar import DateEntry
import datetime

def get_selected_date():
    print(f"Selected date: {cal.get_date()}")

root = tk.Tk()
root.title("tkcalendar DateEntry Demo")

ttk.Label(root, text="Select a date:").pack(padx=10, pady=5)

# Create a DateEntry widget
cal = DateEntry(root, width=12, background='darkblue',
                foreground='white', borderwidth=2,
                year=datetime.date.today().year,
                month=datetime.date.today().month,
                day=datetime.date.today().day,
                date_pattern='dd/MM/yyyy')
cal.pack(padx=10, pady=10)

ttk.Button(root, text="Get Selected Date", command=get_selected_date).pack(pady=5)

root.mainloop()

view raw JSON →