如何在日历中的文本框中选择日期在kivy?

时间:2018-02-06 11:17:58

标签: python python-2.7 kivy kivy-language

我正在使用KivyCalendar。当我从calendar选择日期时,则会出错。

   File "/usr/lib/python2.7/dist-packages/kivy/uix/behaviors/button.py", line 151, in on_touch_down
     self.dispatch('on_press')
   File "kivy/_event.pyx", line 714, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7681)
   File "kivy/_event.pyx", line 1225, in kivy._event.EventObservers.dispatch (kivy/_event.c:13524)
   File "kivy/_event.pyx", line 1149, in kivy._event.EventObservers._dispatch (kivy/_event.c:13050)
   File "/usr/local/lib/python2.7/dist-packages/KivyCalendar/calendar_ui.py", line 218, in get_btn_value
     self.parent_popup.dismiss()
 AttributeError: 'CalendarWidget' object has no attribute 'parent_popup'

有人可以告诉我在从TextBox选择日期后如何在calendar中加价吗? 任何建议或指导将不胜感激.. !!

demo.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.popup import Popup
from KivyCalendar import CalendarWidget
from kivy.core.window import Window

Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (400, 250)

class SetIndex(BoxLayout):
    def __init__(self):
        super(SetIndex, self).__init__()
        #self.init_ui()

    def setDate(self):
        self.cal = CalendarWidget(as_popup=True)
        self.popup = Popup(title='Calendar', content=self.cal, size_hint=(1, 1))
        self.popup.open()


class Demo(App):
    def build(self):
        return SetIndex()


if __name__ == '__main__':
    Demo().run()

demo.kv

<SetIndex>:
    BoxLayout:
        orientation: "vertical"
        padding : 20, 20
        size_hint_y: .5

        BoxLayout:
            orientation: "horizontal"
            padding: 10, 10
            spacing: 10, 10
            size_hint_x: .6

            Label:
                text: "TEXT"
                text_size: self.size
                valign: 'middle'
                size_hint_x: .2

            TextInput:
                size_hint_x: .4
                id: old_date
                on_focus: root.setDate()

0 个答案:

没有答案