Python 2.7 从ttkcalendar小部件返回单击的日期

Python 2.7 从ttkcalendar小部件返回单击的日期,python-2.7,tkinter,Python 2.7,Tkinter,我正在尝试在现有tkinter中使用此日历小部件。我想返回单击的日期,这样我就可以用它做事情了。我试着像这样调用pressed函数 from ttkcalendar import * def clicked(event): print cal.selection() ... root = Tk() cal=Calendar(mainframe) cal.bind("<Button-1>",clicked) 从ttkcalen

我正在尝试在现有tkinter中使用此日历小部件。我想返回单击的日期,这样我就可以用它做事情了。我试着像这样调用pressed函数

 from ttkcalendar import *
    def clicked(event):
        print cal.selection()
    ...
    root = Tk()
    cal=Calendar(mainframe)
    cal.bind("<Button-1>",clicked)
从ttkcalendar导入*
已单击的定义(事件):
打印校准选择()
...
root=Tk()
cal=日历(大型机)
cal.bind(“,单击)
但是,这将返回一个类型错误:“datetime.datetime”对象不可调用。建议?我相信有一个正确的方法来做到这一点…提前感谢

方法
selection()
具有decorator
@属性
,因此您应该执行以下操作:

def clicked(event):
    print cal.selection
    # i.e. not cal.selection()

非常感谢!只是澄清一下,在选择定义之前使用@property使其成为属性?我对python相当陌生,假设使用def name(self)将是一个与其他任何函数一样的函数。@user3883010它不使其成为属性,但您可以按其属性调用函数。