HowTos

Widget styling

Calendar

All styling is done using options, see the documentation.

DateEntry

DateEntry inherits from ttk.Entry therefore the styling is done using a ttk style:

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

from tkcalendar import DateEntry

style = ttk.Style()
# style.theme_use('clam')  # -> uncomment this line if the styling does not work
style.configure('my.DateEntry',
                fieldbackground='light green',
                background='dark green',
                foreground='dark blue',
                arrowcolor='white')

dateentry = DateEntry(style='my.DateEntry')
dateentry.pack()

tk.mainloop()

If the style of the DateEntry does not change, then it might be because of the used ttk theme. Changing the theme with style.theme_use('clam') should solve the issue.

PyInstaller

When bundling an application with PyInstaller, there is an issue (#32) with the detection of the babel dependency of tkcalendar. This can be fixed by using the --hidden-import option:

$ pyinstaller --hidden-import babel.numbers myscript.py

or by editing the .spec file:

hiddenimports=["babel.numbers"]

Custom date formatting

When using the “en_US” locale, the default date formatting in the DateEntry, or when getting the selected date from the Calendar as a string is M/d/yy, i.e. July 4, 2019 will give “7/4/19”. If you want to get “07/04/2019” instead, you can pass “MM/dd/yyyy” to the date_pattern option of the Calendar or DateEntry.

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

from tkcalendar import DateEntry

DateEntry(locale='en_US').pack()
DateEntry(locale='en_US', date_pattern='MM/dd/yyyy').pack()

tk.mainloop()