Reputation: 117
I want to Write something in my TextInput Box with My VKeyboard in kivy language . but it's not work. I've use json for VKeyboard becouse I not found another way for it. if you know how can I use VKeyboard plz tell me .
I want to use VKeyboard on .kv file
this is my code (kivy code with kv file ):
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.uix.screenmanager import ScreenManager , Screen
from kivy.uix.image import Image
from kivy.core.window import Window
from kivy.base import runTouchApp
from kivymd.app import MDApp
from kivy.clock import Clock
from kivy.properties import StringProperty
from kivy.uix.vkeyboard import VKeyboard
class StartTestBtn(Screen):
def read_data(self):
print(self.ids.ti.text)
class WindowManager(ScreenManager):
pass
Builder.load_string("""
#:import utils kivy.utils
<WindowManager>:
StartTestBtn:
<StartTestBtn>:
name: "startTestBtn"
BoxLayout:
cols:1
orientation: "vertical"
size: root.width , root.height
padding: 100, 300, 300 , 500
TextInput:
id : ti
text : ti.text
multiline:False
size_hint_x: 1
height: 50
size_hint_y: None
width: 200
hint_text: "Enter User ID"
icon_right: "account"
font_size:24
BoxLayout:
cols:1
orientation: "vertical"
size: root.width , root.height
padding: 1000, 30, 30 , 400
VKeyboard:
layout: 'numeric.json'
""")
class Shenacell(MDApp):
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "BlueGray"
return WindowManager()
if __name__ == '__main__' :
Shenacell().run()
and this is my json file :
{
"title": "Qwerty",
"description": "A classical US Keyboard",
"cols": 15,
"rows": 5,
"normal_1": [
["`", "`", "`", 1], ["1", "1", "1", 1], ["2", "2", "2", 1],
["3", "3", "3", 1], ["4", "4", "4", 1], ["5", "5", "5", 1],
["6", "6", "6", 1], ["7", "7", "7", 1], ["8", "8", "8", 1],
["9", "9", "9", 1], ["0", "0", "0", 1], ["-", "-", "-", 1],
["=", "=", "=", 1], ["\u232b", null, "backspace", 2]
],
"normal_2" : [
["\u21B9", "\t", "tab", 1.5], ["q", "q", "q", 1], ["w", "w", "w", 1],
["e", "e", "e", 1], ["r", "r", "r", 1], ["t", "t", "t", 1],
["y", "y", "y", 1], ["u", "u", "u", 1], ["i", "i", "i", 1],
["o", "o", "o", 1], ["p", "p", "p", 1], ["[", "[", "[", 1],
["]", "]", "j", 1], ["\\", "\\", "\\", 1]
],
"normal_3": [
["\u21ea", null, "capslock", 1.8], ["a", "a", "a", 1], ["s", "s", "s", 1],
["d", "d", "d", 1], ["f", "f", "f", 1], ["g", "g", "g", 1],
["h", "h", "h", 1], ["j", "j", "j", 1], ["k", "k", "k", 1],
["l", "l", "l", 1], [":", ":", ":", 1], ["'", "'", "'", 1],
["\u23ce", null, "enter", 2.2]
],
"normal_4": [
["\u21e7", null, "shift", 2.5], ["z", "z", null, 1], ["x", "x", "x", 1],
["c", "c", "c", 1], ["v", "v", "v", 1], ["b", "b", "b", 1],
["n", "n", "n", 1], ["m", "m", "m", 1], [",", ",", ",", 1],
[".", ".", ".", 1], ["/", "/", "/", 1], ["\u21e7", null, "shift", 2.5]
],
"normal_5": [
[" ", " ", "spacebar", 12], ["\u2b12", null, "layout", 1.5], ["\u2a2f", null, "escape", 1.5]
],
"shift_1": [
["~", "~", "~", 1], ["!", "!", "!", 1], ["@", "@", "@", 1],
["#", "#", "#", 1], ["$", "$", "$", 1], ["%", "%", "%", 1],
["^", "^", null, 1], ["&", "&", "&", 1], ["*", "*", "*", 1],
["(", "(", "(", 1], [")", ")", ")", 1], ["_", "_", "_", 1],
["+", "+", "+", 1], ["\u232b", null, "backspace", 2]
],
"shift_2": [
["\u21B9", "\t", "tab", 1.5], ["Q", "Q", null, 1], ["W", "W", null, 1],
["E", "E", "e", 1], ["R", "R", "r", 1], ["T", "T", "t", 1],
["Y", "Y", "y", 1], ["U", "U", "u", 1], ["I", "I", "i", 1],
["O", "O", "o", 1], ["P", "P", "p", 1], ["{", "{", "{", 1],
["}", "}", "}", 1], ["|", "|", "|", 1.5]
],
"shift_3": [
["\u21ea", null, "capslock", 1.8], ["A", "A", "a", 1], ["S", "S", "s", 1],
["D", "D", "d", 1], ["F", "F", "f", 1], ["G", "G", "g", 1],
["H", "H", "h", 1], ["J", "J", "j", 1], ["K", "K", "k", 1],
["L", "L", "l", 1], [";", ";", ";", 1], ["\"", "\"", "\"", 1],
["\u23ce", null, "enter", 2.2]
],
"shift_4": [
["\u21e7", null, "shift", 2.5], ["Z", "Z", "z", 1], ["X", "X", "x", 1],
["C", "C", "c", 1], ["V", "V", "v", 1], ["B", "B", "b", 1],
["N", "N", "n", 1], ["M", "M", "m", 1], ["<", "<", "<", 1],
[">", ">", ">", 1], ["?", "?", "?", 1.5], ["\u21e7", null, "shift", 2.5]
],
"shift_5": [
[" ", " ", "spacebar", 12], ["\u2b12", null, "layout", 1.5], ["\u2a2f", null, "escape", 1.5]
]
}
Upvotes: 0
Views: 564
Reputation: 1
The above answer does not work.
Sure the keyboard is displayed, but nothing typed on the virtual keyboard appears in the TextInput box. I would really like to know the answer, too. I am not allowed to comment so I'm posting this as an answer.
Upvotes: 0
Reputation: 38822
At the very top of your python code, insert:
from kivy.config import Config
Config.set('kivy', 'keyboard_mode', 'systemanddock')
This will cause a virtual keyboard to popup for any widget that needs keyboard input.
Then, in your kv
add a rule for VKeyboard
to get your customized keyboard (you can leave this out to get the standard VKeyboard
):
<VKeyboard>:
layout: 'numeric.json'
Upvotes: 1