我编写了一个小kivy程序,因为我想学习如何使用.json文件保存值。
我查阅了文件,发现了这个:http://kivy.org/docs/api-kivy.storage.html#module-kivy.storage
我试图用类似的方法,但是我得到了错误:ImportError: No module named storage.jsonstore
为什么不管用?在
这是我的代码:
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.storage.jsonstore import JsonStore
from kivy.properties import StringProperty
from kivy.properties import NumericProperty
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
class Layout(BoxLayout):
def save(self, vinput):
store = JsonStore('hello.json')
store.put('tito', inpud=vinput)
ROOT = Builder.load_string('''
BoxLayout:
orientation: 'vertical'
TextInput:
id:my_textinput
Button:
text: 'save'
Button:
text: 'acsess'
''')
class Caption(App):
def build(self):
Window.clearcolor = (0, 0, 1, 1)
return ROOT
if __name__ == '__main__':
Caption().run()
我以前从未使用过JsonStore,我会先看看,然后会更新答案,但现在,您可以这样做。在
编辑:1
它实际上工作得非常好。 试试这个改进的代码。在
你的文件
^{pr2}$你的.kv文件
相关问题 更多 >
编程相关推荐