j4321 / tkcalendar

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

Calendar doesn't return date in selected format #102

Closed betson-fernando closed 1 year ago

betson-fernando commented 1 year ago

I'm using tkcalendar, and my (cutted) code is as follow:

import tkinter as tk
import tkcalendar

#Some stuff

def getDay(event):
    global CONT
    CONT+=1
    day=cal.selection_get()
    updateWk(day)

# Some stuff

cal = tkcalendar.Calendar(master=cal_frm, mindate=datetime(esc_year, esc_month, 1), maxdate=max_day, showweeknumbers=False, showothermonthdays=False, date_pattern="dd/mm/yyyy", locale="pt_BR")
cal.grid(row=1, column=0, padx=100, pady=10)
cal.bind("<<CalendarSelected>>", getDay)

But, despite date_pattern="dd/mm/yyyy", cal.selectionget() returns date in format yyyy-mm-dd. Looking the source, I found [that](https://github.com/j4321/tkcalendar/blob/0c6aa7cb4ee1e583bdf0faec62f99f760f192895/tkcalendar/calendar.py#L265-L288):

        if self._textvariable is not None:
            # the variable overrides day, month and year keywords
            try:
                self._sel_date = parse_date(self._textvariable.get(), locale)
                month = self._sel_date.month
                year = self._sel_date.year
            except IndexError:
                self._sel_date = None
                self._textvariable.set('')
                month = kw.pop("month", today.month)
                year = kw.pop('year', today.year)
        else:
            if (("month" in kw) or ("year" in kw)) and ("day" not in kw):
                month = kw.pop("month", today.month)
                year = kw.pop('year', today.year)
                self._sel_date = None  # selected day
            else:
                day = kw.pop('day', today.day)
                month = kw.pop("month", today.month)
                year = kw.pop('year', today.year)
                try:
                    self._sel_date = self.date(year, month, day)  # selected day
                except ValueError:
                    self._sel_date = None

At this snippet, if _textvariable is None, so self._sel_date = self.date(year, month, day) (here)

My suggestion is call function format_date at line above, as that:

self._sel_date = self.format_date(self.date(year, month, day))

I'm new in coding universe, so I'm learning to use github. Because that, I fear to make any code changes in a wrong way, justifying only this issue raising. If someone wants help me about effectively change this code to return the correct pattern, I'll be grateful.

Wolf-SO commented 1 year ago

@betson-fernando I'm not sure if I'm the one you will eventually help you here. But in general, a closed issue doesn't get anyone to even begin to think about a solution. So at lease re-open it and see what the future holds.

betson-fernando commented 1 year ago

Dear, thanks for your help!

Really, I learned a lot about tkcalendar yesterday and today. So, I saw that I was wrong about my issue.

I did try to delete the issue, but I didn't know how to do it. So, the best way that I found was to close it.

I like much to code, and help the development of important things, but inexperience has some weight yet. :)

So, thanks for your answer. Probably in few time I'll be more assertive about Computer Science.

Best regards. Betson

Em dom., 5 de mar. de 2023 07:31, Wolf-SO @.***> escreveu:

@betson-fernando https://github.com/betson-fernando I'm not sure if I'm the one you will eventually help you here. But in general, a closed issue doesn't get anyone to even begin to think about a solution. So at lease re-open it and see what the future holds.

— Reply to this email directly, view it on GitHub https://github.com/j4321/tkcalendar/issues/102#issuecomment-1455050892, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANWPWEZWVYDU3SQ575KBM7DW2RTQBANCNFSM6AAAAAAVQBJC6E . You are receiving this because you were mentioned.Message ID: @.***>