I have a tkcalendar and it's pre-defined widget for Calendar, DateEntry and am trying to get the User's selected date for DateEntry. Whereas there is provision to extract the selected date for the Calendar widget using "selection_get()" but nothing for DateEntry that I could find.
I have tried get_date(),get(),_date(), cget(), ._selection() amongst many others but they don't seem to return/print the user-selected date. Please help, kindly let me know if any added information is needed
Code [picked from a simple tkcalendar tutorial]:
import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar, DateEntry
def calendar_view():
def print_sel():
print(cal.selection_get())
top = tk.Toplevel(root)
cal = Calendar(top,
font="Arial 14", selectmode='day',
cursor="hand1", year=2018, month=2, day=5)
cal.pack(fill="both", expand=True)
ttk.Button(top, text="ok", command=print_sel).pack()
def dateentry_view():
top = tk.Toplevel(root)
ttk.Label(top, text='Choose date').pack(padx=10, pady=10)
cal = DateEntry(top, width=12, background='darkblue',
foreground='white', borderwidth=2)
cal.pack(padx=10, pady=10)
print(cal.cget(DateEntry))
root = tk.Tk()
s = ttk.Style(root)
s.theme_use('clam')
ttk.Button(root, text='Calendar', command=calendar_view()).pack(padx=10, pady=10)
ttk.Button(root, text='DateEntry', command=dateentry_view()).pack(padx=10, pady=10)
root.mainloop()