pythontkinterdatepickertkcalendar

Change date format in Tkinter date picker - python


As title say, I would like to change the date format in Tkinter from m/d/y to dd/mm/yyyy

I have the following code but did not work. still the format of the date is 2/16/2022

root = tk.Tk()
root.geometry("700x450")


#Weekly From
cal1 = DateEntry(root, width=8, year=year, month=month, day=day,
background='darkblue', foreground='white', borderwidth=2, locale = 'en_us', date_patern ='dd.mm.yyyy')
cal1.place(x=150, y=50)

#Weekly to
cal2 = DateEntry(root, width=8, year=year, month=month, day=day,
background='darkblue', foreground='white', borderwidth=2, locale = 'en_us', date_patern ='dd.mm.yyyy')
cal2.place(x=240, y=50)

Solution

  • reference:- Python Tkinter Tk Calendar get custom date not working and unable to display date in format: "DD-MM-YYYY"

    You could do something like this:-

    from tkinter import *
    from tkcalendar import *
    root=Tk()
    root.geometry("500x500")
    def mainF():
        global cal
        def getDate():
            date=cal.get_date()
            print(date)
        cal.pack(pady=20, padx=20)
        butt=Button(root,text="Date Getter", bg="cyan",command=getDate).pack()
    cal=Calendar(root,selectmode="day",date_pattern="dd-mm-y")
    but=Button(root,text="Pick Date",command=mainF).pack()
    root.mainloop()
    

    this is a small date picker app, that changes the format to dd-mm-yy instead of mm-dd-yy, you can implement format change in your code like this