In this video I’ll show you how to use the KivyMD Date Picker for Kivy and Python.
In this video we’ll look at the KivyMD DatePicker that allows you to pull up a calendar and pick a date, and then return that date to the screen. We can set a default day, or grab a range of dates or an individual date. We’ll look at all those options in this video.
#kivy #codemy
Python Code: date.py
GitHub Code: date.py
from kivy.lang import Builder from kivymd.app import MDApp from kivymd.uix.picker import MDDatePicker class MainApp(MDApp): def build(self): self.theme_cls.theme_style = "Light" self.theme_cls.primary_palette = "BlueGray" return Builder.load_file('date.kv') # Click OK def on_save(self, instance, value, date_range): #print(instance, value, date_range) #self.root.ids.date_label.text = str(value) self.root.ids.date_label.text = f'{str(date_range[0])} - {str(date_range[-1])}' # Click Cancel def on_cancel(self, instance, value): self.root.ids.date_label.text = "You Clicked Cancel" def show_date_picker(self): #date_dialog = MDDatePicker(year=2000, month=2, day=14) date_dialog = MDDatePicker(mode="range") date_dialog.bind(on_save=self.on_save, on_cancel=self.on_cancel) date_dialog.open() MainApp().run()
Kivy Design Code: date.kv
GitHub Code: date.kv
MDFloatLayout: MDRaisedButton: text: "Open Date Picker" pos_hint: {'center_x': .5, 'center_y': .5} on_release: app.show_date_picker() MDLabel: id: date_label text: "Some Stuff!" pos_hint: {'center_x': .95, 'center_y': .4}
Add comment