Reputation: 406
How to use DatePicker
based on TextInput
?When textinput
field focused shows popup with CalendarWidget
.Once data selected then selected date don't put into textinput
field.
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__()
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()
<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()
Upvotes: 0
Views: 2494
Reputation: 358
Which python version do you use?
KivyCalendar is a dated library written with 2.7 python version in mind, it does not work with 3.6 python at all.
Unless you are willing to use an unsupported, dated library, I would advice you to find an alternative.
UPD: Okay, so I could not find any alternatives, here is how this library work: You need to setup a DatePicker which is a textinput with all the necessary popup/value handling
<SetIndex>:
BoxLayout:
orientation: "vertical"
padding : 20, 20
size_hint_y: .5
DatePicker:
pHint: 1,1
size_hint_x: .4
id: old_date
You actual code only needs to import DatePicker, that is all there is to it
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)
Window.size = (400, 250)
class SetIndex(BoxLayout):
def __init__(self):
super(SetIndex, self).__init__()
class Demo(App):
def build(self):
return SetIndex()
if __name__ == '__main__':
Demo().run()
Upvotes: 2