5

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)
4
  • the potential answer could be:- stackoverflow.com/questions/67597724/… Commented Feb 16, 2022 at 16:21
  • What is DateEntry? That's not part of the standard tkinter package. Commented Feb 16, 2022 at 16:33
  • 2
    Typo: date_patern should be date_pattern instead. Commented Feb 16, 2022 at 16:51
  • @BryanOakley DateEntry is part of the tkcalendar module Commented Feb 16, 2022 at 19:11

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I have not tried you code, but I had a Typo in my code
2

Here is the answer :

cal = DateEntry(c12, width=30, background="green",date_pattern="yyyy-mm-dd")    
cal.grid(row=3, column=1, pady=(10, 0), ipadx=50)

Copy date_pattern="yyyy-mm-dd" and put it inside your entry

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.