更新时间:2023-12-05 08:47:16
我将 kivy 与 pickle 一起使用,它工作正常.
Im using kivy with pickle and it works correctly.
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.config import Config
import pickle
FRAMES_PER_SECOND = 60.0
Config.set('graphics','multisamples',2)
a = []
class Display(BoxLayout):
def save(self,text):
with open('db.prz','wb') as file:
pickle.dump(text,file)
def loads(self):
with open('db.prz','rb') as file:
a = pickle.load(file)
print(a)
class TestApp(App):
def build(self):
a = Display()
return a
if __name__ == '__main__':
TestApp().run()
kv 文件:
<Display>:
BoxLayout:
orientation: 'vertical'
TextInput:
id: kvtext
size_hint_y : 0.2
BoxLayout:
orientation : 'horizontal'
Button:
text: 'Save'
on_press: root.save(kvtext.text)
Button:
text: 'Load'
on_press: root.loads()
规范文件更改:
# -*- mode: python ; coding: utf-8 -*-
from kivy_deps import sdl2, glew
a = Analysis(
datas=[('C:\\Users\\mnt\\Documents\\build_test\\test.kv','.')],
coll = COLLECT(
*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
请注意,我没有将我的文件 'db.prze' 添加到 Analysis()
Note that im not adding my file 'db.prze' to data in Analysis()
我也是从github而不是pip安装了pyi.
I also installed pyi from github not from pip.
如果您正在加载类对象,请从文件中导入其类.
If you are loading class object, import its class from file.