In this video I’ll show you how to use the VKeyboard With Kivy.

It’s pretty easy to add a Keyboard to your app using VKeyboard. I’ll show you how in this video.

We’ll also write special code for the Backspace and Spacebar Button.

#kivy #codemy

Python Code: vkey.py
GitHub Code: vkey.py

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.vkeyboard import VKeyboard
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout


class MainApp(MDApp):

	def build(self):
		self.theme_cls.theme_style = "Dark"
		self.theme_cls.primary_palette = "BlueGray"

		# Define Our Layout
		layout = GridLayout(cols=1)
		# Define Our VKeyboard
		keyboard = VKeyboard(on_key_up = self.key_up)

		self.label = Label(text="Type Something!", font_size = "20sp")

		layout.add_widget(self.label)
		layout.add_widget(keyboard)

		return layout

	def key_up(self, keyboard, keycode, *args):
		if isinstance(keycode, tuple):
			keycode = keycode[1]

		# Tracking what was already in the label
		thing = self.label.text
		
		# Run some logic
		if thing == "Type Something!":
			thing = ''
		# Backspace
		if keycode == 'backspace':
			thing = thing[:-1]
			keycode = ''
		# Spacebar
		if keycode == 'spacebar':
			keycode = " " 

		# Update the label
		self.label.text = f'{thing}{keycode}'

MainApp().run()		

John Elder

John is the CEO of Codemy.com 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