j4321 / tkcalendar

Calendar widget for Tkinter
https://pypi.python.org/pypi/tkcalendar
GNU General Public License v3.0
97 stars 33 forks source link

Weird click offset in Calendar widget for January 2023 #99

Open justindubin opened 1 year ago

justindubin commented 1 year ago

I developed an application for work which leverages the tkcalendar Calendar widget. I noticed that for January 2023 I'm not able to select the intended date as there is a vertical offset between the mouse pointer and the click target. It's far enough off that I am not even able to select any dates in the first week (row) of the calendar. So far, I have not noticed any issues with other month/year combinations.

This isn't really a severe issue, but I thought I'd let y'all know in case this is related to something more serious. In the below image, I clicked on Jan 3, but Jan 10 gets selected. This occurs for every date in January with the sole exception on Jan 1.

image

Dasuke commented 1 year ago

I'm having the same issue, I "could fix" this changing the firstweekday='sunday' to firstweekday='monday'.

photodude commented 1 year ago

Duplicate of issue #98

jemiele1 commented 1 year ago

This problem occurs for any year where January 1 is a Sunday and firstweekday is set to "sunday".

The fix (hack) that I came up with was to modify function _get_day_coords. The if statement that checks for the firstweekday == 'sunday' has three new lines at the end Here is the entire if statement:

        if self['firstweekday'] == 'sunday':
            d %= 7
            if d == 0:
                w += 1
            if dn == 7:
                wn += 1
            if date.month == 1 and calendar.datetime.date(date.year,date.month,1).strftime("%A") == "Sunday":
                w = int(date.strftime("%U")) - 1
                wn = 0     

This little hack checks if the current month is January and if January 1 of the current year falls on a Sunday. If so, it sets w to the week number returned by strftime instead of isocalendar and sets wn to zero. That fixes the January problem for years where January 1 is on a Sunday and the firstweekday = 'sunday' without messing up any other months.