Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Created January 31, 2020 03:34
Show Gist options
  • Save tshirtman/b79576f3c8739c886c3667c063eefd3e to your computer and use it in GitHub Desktop.
Save tshirtman/b79576f3c8739c886c3667c063eefd3e to your computer and use it in GitHub Desktop.
an example of customizing keyboard widget in multi mode in kivy
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemandmulti')
from kivy.app import App
from kivy.lang import Builder
from kivy.factory import Factory
from kivy.animation import Animation as A
from kivy import properties as P
KV = '''
<KeyboardTextInput>:
size_hint_y: None
height: self.minimum_height
target_pos: self.center_x, self.y
multiline: False
GridLayout:
cols: 2
padding: 100
spacing: 20
KeyboardTextInput:
KeyboardTextInput:
KeyboardTextInput:
KeyboardTextInput:
'''
class KeyboardTextInput(Factory.TextInput):
target_pos = P.ListProperty([0, 0])
def on_keyboard(self, *args, **kwargs):
# super().on_keyboard(*args, **kwargs)
if self.keyboard and self.keyboard.widget:
w = self.keyboard.widget
# w.layout = 'custom-keyboard.json'
w.do_scale = False
w.do_rotation = False
if w.scale == 1:
w.center_x = app.root.center_x
w.scale = .5
w.top = app.root.y
w.opacity = 0
w.center_x = self.target_pos[0]
w.top = self.target_pos[1] - 20
A(
opacity=1,
center_x=self.target_pos[0],
top=self.target_pos[1],
scale=1.2,
t='out_sine',
d=.5
).start(w)
class Application(App):
def build(self):
return Builder.load_string(KV)
if __name__ == "__main__":
app = Application()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment