Expanding dateentry display from m/d/yy to mm/dd/yyyy?
This is possible without overriding _select
since version 1.5.0, using the date_pattern
argument (See documentation):
import tkinter as tkfrom tkcalendar import DateEntrywindow = tk.Tk()DateEntry(window, locale='en_US', date_pattern='mm/dd/y').pack() # custom formattingDateEntry(window, locale='en_US').pack() # default formattingwindow.mainloop()
gives
If you just want to change how it appears upon selection, you can make a class that inherit DateEntry
and override the _select
method.
from tkcalendar import DateEntryimport tkinter as tkroot = tk.Tk()class CustomDateEntry(DateEntry): def _select(self, event=None): date = self._calendar.selection_get() if date is not None: self._set_text(date.strftime('%m/%d/%Y')) self.event_generate('<<DateEntrySelected>>') self._top_cal.withdraw() if 'readonly' not in self.state(): self.focus_set()entry = CustomDateEntry(root)entry._set_text(entry._date.strftime('%m/%d/%Y'))entry.pack()root.mainloop()