我想获取 tkcalendar 日历的选定日期,但它抛出了一个AttributeError: 'NoneType' object has no attribute 'get_date'
,我不知道为什么。
有人可以帮助我吗?
这是我的代码:
class Main(Frame):
def __init__(self, parent):
super(Main, self).__init__(parent)
padding = 10
# calenders
mainCalendarFrame = Frame(root)
# start
startCalendarFrame = Frame(mainCalendarFrame)
startLabel = Label(startCalendarFrame, text='Start').pack(fill=X, pady=(0, padding))
self.startCalendar = Calendar(startCalendarFrame, selectmode='day', year=int(date.today().strftime('%Y')), month=int(date.today().strftime('%m')), day=int(date.today().strftime('%d'))).pack(fill=X, pady=(0, 5))
mainCalendarFrame.pack(padx=padding, pady=padding)
settingsFrame.pack(fill=X, padx=padding, pady=padding)
btnCalculate.pack(fill=X, padx=padding, pady=padding)
def btn_click(self):
print(self.startCalendar.get_date())