tkcalendar
tkcalendar copied to clipboard
DateEntry date_pattern parsing in yyyyMMdd format fails
DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyyMMdd')
Other variants attempted: DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyy-MMdd') DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyyMM-dd')
Succeeds: DateEntry(prodfrm, width= 16,bd=2, date_pattern='yyyy-MM-dd')
Error message:
Exception in Tkinter callback Traceback (most recent call last): File "C:\Python38\lib\tkinter_init_.py", line 1883, in call return self.func(*args) File "C:\Python38\lib\site-packages\tkcalendar\dateentry.py", line 246, in on_b1_press self.drop_down() File "C:\Python38\lib\site-packages\tkcalendar\dateentry.py", line 331, in drop_down date = self.parse_date(self.get()) File "C:\Python38\lib\site-packages\tkcalendar\calendar.py", line 1229, in parse_date day = int(numbers[indexes['D']]) IndexError: list index out of range
This appears to be an issue because the calendar parse date method is looking for regex groupings instead of matching the particular pattern exactly. Perhaps this could be improved by reading the length of digits == length of the number of letters matching (YY vs YYYY) and using those values instead of just the groupings.
Alternatively, you can also use python tools to accomplish this via strptime: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
Formatting would be different, but could a good solution that is versatile without much effort required. The downside of this is combability breaking for users who update the library to use in existing projects.