【问题标题】:Python Calendar WidgetPython 日历小部件
【发布时间】:2013-03-24 14:44:07
【问题描述】:

我发现this Python 日历小部件虽然this post。我正在尝试打印出用户在日历上选择的日期。我尝试的是这样的

mycalendar=Calendar()
print mycalendar.selection()

我知道仅此一小段代码并不能说明问题。 "Calendar" 是一个类,而 selection(self) 是 Calendar 类中的一个函数,具有返回值。为了清楚理解,请参阅我上面提供的链接,因为代码太长,无法在此处发布。

我的问题是一旦我运行脚本,而不是给我函数的返回号,它给了我这个错误消息“TypeError:'NoneType' object is not callable”。有没有办法让用户在日历上选择的日期打印出来?

【问题讨论】:

    标签: python calendar tkinter


    【解决方案1】:

    在您发布的课程中,_pressed 函数在用户在日历窗口内单击鼠标后被调用。

    要打印日期,请在以下代码块后添加print self.selection:

        # update and then show selection
        text = '%02d' % text
        self._selection = (text, item, column)
        self._show_selection(text, bbox)
    
        print self.selection  # print the date selected to the console
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多