在 Tkinter 日期选择器中更改日期格式 - python
Change date format in Tkinter date picker - python
正如标题所说,我想将 Tkinter 中的日期格式从 m/d/y 更改为 dd/mm/yyyy
我有以下代码但没有用。日期格式仍然是 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)
参考:-
你可以这样做:-
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()
这是一个小型日期选择器应用,将格式更改为 dd-mm-yy 而不是 mm-dd-yy,您可以像这样在代码中实现格式更改
正如标题所说,我想将 Tkinter 中的日期格式从 m/d/y 更改为 dd/mm/yyyy
我有以下代码但没有用。日期格式仍然是 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)
参考:-
你可以这样做:-
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()
这是一个小型日期选择器应用,将格式更改为 dd-mm-yy 而不是 mm-dd-yy,您可以像这样在代码中实现格式更改