In this video I’ll show you how to use the KivyMD Time Picker for Kivy and Python.

In this video we’ll look at the KivyMD TimePicker that allows you to pull up a clock and pick a time, and then return that time to the screen. We can set a default time as well. We’ll look at all those options in this video.

#kivy #codemy

Python Code:
GitHub Code:

from kivy.lang import Builder
from import MDApp
from kivymd.uix.picker import MDTimePicker

class MainApp(MDApp):
	def build(self):
		self.theme_cls.theme_style = "Light"
		self.theme_cls.primary_palette = "BlueGray"
		return Builder.load_file('time.kv')

	# Get Time
	def get_time(self, instance, time):
		self.root.ids.time_label.text = str(time)

	# Cancel
	def on_cancel(self, instance, time):
		self.root.ids.time_label.text = "You Clicked Cancel!"

	def show_time_picker(self):
		from datetime import datetime

		# Define default time
		default_time = datetime.strptime("4:20:00", '%H:%M:%S').time()

		time_dialog = MDTimePicker()
		# Set default Time
		time_dialog.bind(on_cancel=self.on_cancel, time=self.get_time)

Kivy Design Code: time.kv
GitHub Code: time.kv


		text: "Open Time Picker"
		pos_hint: {'center_x': .5, 'center_y': .5}
		on_release: app.show_time_picker()

		id: time_label
		text: "Some Stuff!"
		pos_hint: {'center_x': .95, 'center_y': .4}

John Elder

John is the CEO of where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder