为什么我的 tkcalendar 年份错误?

问题描述 投票:0回答:1

我的 tkcalendar 条目将 2000 年之前的年份设置为 2000,例如,如果您回答您的生日是 1986 年,则认为您出生于 2086 年。

birthDateEntry = DateEntry(root, width=12,background='darkblue', foreground='white', borderwidth=2,font = ("Copperplate Gothic Light", 10))

student = Student(fullNameEntrada.get(), birthDateEntry.get_date().strftime("%m/%d/%Y").replace("-", "/"))
        #For a 5/13/1989 it returns
        print(birthDateEntry.get()) #Return 5/13/2089
        print(birthDateEntry.get_date()) #Return 2089-05-13
#student class
class Student():
    
    def __init__(self, name, birthdate):
        self.name = name
        self.birthdate = birthdate
        self.age = self.getAge()
        self.registerDate=str(date.today().strftime("%m/%d/%Y").replace("-", "/"))      
        self.connection = sqlite3.connect('students.db')
        self.cursor = self.connection.cursor()
        self.createTable()


#getAge Method on student class
def getAge(self):
        today = date.today()
        birthyear = self.birthdate.split()
        self.age = today.year - int(birthyear[0][6:])
        return self.age```
python tkinter calendar
1个回答
0
投票

尝试使用这种格式 datetime.today().strftime('%m-%d%-%Y')

© www.soinside.com 2019 - 2024. All rights reserved.