j4321 / tkcalendar

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

Modified format date #64

Closed fcarpentey75012 closed 4 years ago

fcarpentey75012 commented 4 years ago

Hi,

First time, thanks you for your code. I have a problem with the format date, because i work with Year-Month-Day and your date displayed in format Month-Day-Years. Do you have an solution for modified the format ? I search strftime or others in DateEntry but i didn't find informations.

Do you have idea for resolved my problem ?

Thanks you for your time and your help !

import pandas as pd

from tkcalendar import DateEntry
from datetime import date

def test_cal():
    window = call_mise_en_forme()
    window.mainloop()

class MyDateEntry(DateEntry):
    def __init__(self, master=None, **kw):
        DateEntry.__init__(self, master=None, **kw)
        # add black border around drop-down calendar
        self._top_cal.configure(bg='black', bd=1)
        # add label displaying today's date below
        tk.Label(self._top_cal, bg='gray90', anchor='w',
                 text='Today : %s' % date.today().strftime('%d-%m-%Y')).pack(fill='x')

class call_mise_en_forme(Tk):
    def __init__(self):
        Tk.__init__(self)
        global liste_name, df,liste_old_name,liste_new_name, liste_taille, liste_police
        self.geometry( "200x120" )
        self.title( "Fonction de mise en forme" )

        self.save_format = StringVar(value='Nom du format')
        self.field_colonnes = StringVar(value='Nom colonne')
        self.field_taille = StringVar(value='Taille police')
        self.field_police = StringVar(value='Police caractere')
        self.field_RGB = StringVar(value='(255,255,255)')
        Mise_en_Forme = ('Proxima Nova', '8')

        liste_old_name = []
        liste_new_name = []
        liste_taille = []
        liste_police = []
# ---------------------------BUTTONS-----------------------------------------------

        self.button = Button(self, text="Enregistrer la mise en forme",command=self.test)
        self.button.pack(side=BOTTOM,fill=X, expand="yes",pady=4,padx =10)

        self.de = MyDateEntry(self, year=2019,day=19, month=12)

        self.de.focus_set()
        self.de.pack()

    def test(self):
        print(self.de.get())
        a = (self.de.get()).replace("/", "-")
        print(a)

def reverse(string): 
    string = string[::-1] 
    return string         

test_cal()
j4321 commented 4 years ago

If you are using tkcalendar >= 1.5.0, there is the date_pattern option to customize the date format. See https://tkcalendar.readthedocs.io/en/stable/howtos.html#custom-date-formatting. In your case you will need to use date_pattern='yyyy-MM-dd'.