我试图腌制一个kivy对象,但我收到了以下错误:
TypeError: can't pickle hands_screen objects
这是我的代码:
class ranges_app(App):
def build(self):
return screen()
def pickle_object(self, name, obj):
with open(name + '.pickle', 'wb') as f:
pickle.dump(obj, f, protocol = pickle.HIGHEST_PROTOCOL)
def on_stop(self):
app = App.get_running_app()
f = app.root.manager.utg
print(f.name)
self.pickle_object(f.name, f.h)
class big_screen(Screen):
def __init__(self, **kwargs):
super(big_screen, self).__init__(**kwargs)
self.h = hands_screen()
self.add_widget(self.h)
class hands_screen(GridLayout):
def __init__(self, **kwargs):
super(hands_screen, self).__init__(**kwargs)
self.l = ['A', 'K', 'Q', 'J', 'T'] + [str(i) for i in range(9,1,-1)]
self.cols = 13
self.rows = 13
for i in range(13):
for j in range(13):
self.add_widget(hand_button(text = [str(self.l[i])+str(self.l[j]) + 's', str(self.l[j]) + str(self.l[i])+'o', str(self.l[j]) + str(self.l[i])][(i>j) - (i == j)]))
有没有办法解决这个错误或一般保存一个kivy对象?