I am using python-2.7
and kivy. When i click on cross.png
then calendar open. When i click into calendar then how to get selected date? Actually i need to selected date put into TextInput
. Can someone tell me that how to make it possible?
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from KivyCalendar import DatePicker
from kivy.core.window import Window
Window.clearcolor = (0.5, 0.5, 0.5, 1)
class Calendar(BoxLayout):
def __init__(self):
super(Calendar, self).__init__()
def show_calendar(self):
datePicker = DatePicker()
datePicker.show_popup(1,.3)
class Test(App):
def build(self):
return Calendar()
if __name__ == '__main__':
Test().run()
<Calendar>:
BoxLayout:
orientation: "vertical"
padding : 20, 20
size_hint_y: .5
Button:
on_press: root.show_calendar()
Image:
y: self.parent.y
center_x: self.parent.center_x
allow_stretch: True
source: 'cross.png'
TextInput:
text:""
<DatePicker>:
pHint: .3, .3
id: ti
to TextInput widget.update_value()
method.Please refer to example for details.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from KivyCalendar import DatePicker
from kivy.core.window import Window
Window.clearcolor = (0.5, 0.5, 0.5, 1)
class CustomDatePicker(DatePicker):
def update_value(self, inst):
""" Update textinput value on popup close """
self.text = "%s.%s.%s" % tuple(self.cal.active_date)
self.focus = False
App.get_running_app().root.ids.ti.text = self.text
class Calendar(BoxLayout):
def show_calendar(self):
datePicker = CustomDatePicker()
datePicker.show_popup(1, .3)
class Test(App):
def build(self):
return Calendar()
if __name__ == '__main__':
Test().run()
#:kivy 1.11.0
<Calendar>:
BoxLayout:
orientation: "vertical"
padding : 20, 20
size_hint_y: .5
Button:
on_press: root.show_calendar()
Image:
y: self.parent.y
center_x: self.parent.center_x
allow_stretch: True
source: 'cross.png'
TextInput:
id: ti
<DatePicker>:
pHint: .3, .3