How do I run a command on selecting a date in Tkinters DateEntry widget

Viewed 19

I want a function to run when the user selects a new date. But when I add the command, nothing happens. How do I get my command to trigger on selecting a date?

from tkinter import *
from tkcalendar import *
import datetime

root = Tk()
root.geometry('400x400')


def date_change(self):
    print(cal.get_date())


today = datetime.date.today()
yesterday = today - datetime.timedelta(days=1)

cal = DateEntry(root, font=('Helvetica', '15'), height=1, width=7,
                     year=yesterday.year, month=yesterday.month, day=yesterday.day,
                    command=lambda: date_change())
cal.pack()

root.mainloop()
0 Answers
Related