tkcalendar icon indicating copy to clipboard operation
tkcalendar copied to clipboard

Left month button incorrectly disabled in the first year after mindate

Open kofflo opened this issue 4 years ago • 1 comments

In the calendar, when the currently displayed month is in the first year after the mindate, the "left month" button remains incorrectly disabled until a data which is a full year after mindate is reached.

For instance, if mindate is 28 December 2019 and the calendar shows any month of 2020 except December, the left month button remains disabled, basically preventing to go back to previous months.

The problem is due to the following code in calendar_.py (lines 1109 to 1123):

            if dy == 0:
                self._l_year.state(['disabled'])
                if self._date.month == min_month:
                    self._l_month.state(['disabled'])
                else:
                    self._l_month.state(['!disabled'])
            elif dy == 1:
                if self._date.month >= min_month:
                    self._l_year.state(['!disabled'])
                    self._l_month.state(['!disabled']) # -> wrong
                else:
                    self._l_year.state(['disabled'])
            else:  # dy > 1
                self._l_year.state(['!disabled'])
                self._l_month.state(['!disabled']))

The correct code should be:

            if dy == 0:
                self._l_year.state(['disabled'])
                if self._date.month == min_month:
                    self._l_month.state(['disabled'])
                else:
                    self._l_month.state(['!disabled'])
            elif dy == 1:
                if self._date.month >= min_month:
                    self._l_year.state(['!disabled'])
                else:
                    self._l_year.state(['disabled'])
                self._l_month.state(['!disabled']) # -> correct: always enabled
            else:  # dy > 1
                self._l_year.state(['!disabled'])
                self._l_month.state(['!disabled']))

i.e. if we are in the first year after the mindate, the left month button should always be enabled.

Exactly the same problem occurs for maxdate and the right month button at line 1097: self._r_month.state(['!disabled']) should not be inside the inner if-else block.

kofflo avatar Dec 28 '20 15:12 kofflo

Same issue with the right arrow with max_date, and same fix on line 1097. I will make a pull request.

Cielbird avatar Jan 24 '24 16:01 Cielbird