0

我正在尝试将dateVal从“md-yy”格式更改为“yyyy-mm-dd”。dateVal 值通过在日历中选择一个日期获得。

global NewdateVal
def openCalendar():
    def getDate():
        dateVal = cal.get_date()
        NewdateVal = datetime.strptime(dateVal, '%Y-%m-%d')
        #NewdateVal = datetime.date(dateVal, '%d/%m/%y')
        print(NewdateVal)
        return NewdateVal

    calendarFrame = Toplevel()
    cal = Calendar(calendarFrame, selectmode='day', year=2021, month=5, day=1)
    cal.pack()
    SelectDateButton = Button(calendarFrame, text="Choose Date", command=getDate)
    SelectDateButton.pack(pady=20)
    
CalendarLabel = Label(ProjectRequirementsFrame, text="Due Date: ").place(x=450, y=200)
CalendarButton = Button(ProjectRequirementsFrame, text="Select Date", command=openCalendar).place(x=500, y=200)
4

0 回答 0