I have a DateEntry widget and a button to clear the DateEntry contents. I want the DateEntry to be blank unless the user selects a date.
My problem is if I select the DateEntry widget and give it focus, then using the clear button doesn't work the first time because the DateEntry is auto-completing after losing focus.
Example:
from tkinter import *
from tkinter import ttk
from tkcalendar import DateEntry
def clearDateEntry():
clearButton.focus_set()
myDateEntry.delete(0,END)
root=Tk()
myDateEntry=DateEntry(root)
myDateEntry.pack()
myDateEntry.delete(0,END)
clearButton=Button(root,text='clear',command=clearDateEntry)
clearButton.pack()
root.mainloop()
To replicate: give DateEntry focus, then click clear.
In the clearDateEntry()
function, I move the focus to the clear button first which I'd expect would trigger the auto-complete so that I can delete it straight after, but that doesn't work.
How do I make clearDateEntry()
actually clear the DateEntry on the first go? If there's a way to turn off DateEntry's auto-complete, that would also solve my problem.