__Setup_selection () has a binding to the Configure event. Presumably, he should remove the “selection canvas” when the calendar changes. However, the Configure event also fires when the calendar is first displayed on the screen, so your selected date disappears before you see it.
set_day (below) allows you to select a day programmatically. This wraps around the problem of this first Configure event, rescheduling itself if the widget is not yet visible.
Changes to Calendar:
def __setup_selection(self, sel_bg, sel_fg): self._font = font.Font() self._canvas = canvas = tkinter.Canvas(self._calendar, background=sel_bg, borderwidth=0, highlightthickness=0) canvas.text = canvas.create_text(0, 0, fill=sel_fg, anchor='w') canvas.bind('<ButtonPress-1>', lambda evt: canvas.place_forget())
source share