我正在使用带有泡菜的 kivy,它可以正常工作。
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() 中的数据中
我还从 github 而不是从 pip 安装了 pyi。
如果您正在加载类对象,请从文件中导入其类。