Kivy-kv语言VKeyboard

时间:2016-09-08 20:51:18

标签: python widget kivy virtual-keyboard

我想为使用Kivy 1.9.0编写的应用添加VKeyboard小部件。我使用Python 2.7.12。有没有办法通过kv语言将此小部件添加到应用程序?因为在尝试下面的方法时会出现错误:'ValueError:No JSON对象无法解码'

        Button:
            background_color:1,0,0,0.5
            text:'Next word'
            size_hint:.5,.2
            font_size:25
            pos_hint:{'center_x':.5}
            on_press:root.word_dict()

        VKeyboard:
            layout:'layout.json'

layout.json

 { "title":"KeyboardPinyin", "description":"Keyboard using for writing pinyin characters", "cols":5, "rows":3, "normal_1":[ ["ā","ā","ā",1], ["ē","ē","ē",1], ["ī","ī","ī",1], ["ō","ō","ō",1], ["ū","ū","ū",1] ], "normal_2": [ ["á","á","á",1], ["é","é","é",1], ["í","í","í",1], ["ó","ó","ó",1], ["ú","ú","ú",1] ], "normal_3": [ ["ǎ","ǎ","ǎ",1], ["ě","ě","ě",1], ["ǐ","ǐ","ǐ",1], ["ǒ","ǒ","ǒ",1], ["ǔ","ǔ","ǔ",1] ], "normal_4": [ ["à","à","à",1], ["è","è","è",1], ["ì","ì","ì",1], ["ò","ò","ò",1], ["ù","ù","ù",1] ] }

1 个答案:

答案 0 :(得分:0)

Traceback (most recent call last):
  File "C:/Users/joran/.PyCharm50/config/scratches/scratch_33", line 3, in <module>
    data = json.load(open(os.path.expanduser("~/layout1.json")))
  File "C:\Python27\lib\json\__init__.py", line 290, in load
    **kw)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xe1 in position 0: unexpected end of data

你不能尝试使用utf8解码输入...你的json中有非utf8字符

你应该使用unicode表示"\u00e0"等(或者你必须以某种方式指定json的字符编码......我不知道你怎么可能这样做)