我正在制作一个python kivy程序,其中我有不同的屏幕,并且根据不同的屏幕,它们各自的Screen类中的功能也不同,但是现在我想将另一个屏幕类的功能访问到其他类。 这是我的代码:
class CustomSlips(Screen):
def __init__(self,**kwargs):
super(CustomSlips,self).__init__(**kwargs)
slips = []
def input_append(self,list):
for i in range(0,4):
for j in range(0,3):
list.append(list[i])
class DefaultSlips(Screen):
Custom = CustomSlips()
def Flowerscopy(self):
Flowers = ["Rose","Sunflower","Tulips","Marigold"]
Custom.slips = copy.copy(Flowers)
print(Custom.slips)
和kivy文件是:
<CustomSlips>:
name: "CustomSlips"
BoxLayout:
Button:
pos_hint: {"center_x":0.5,"top":0.4}
size_hint: 0.5,1.1
text:"Write On Slips"
on_release:
app.root.transition = SlideTransition(direction = 'left')
app.root.current = "PlayScreen"
root.slips.append(slip1.text)
root.slips.append(slip2.text)
root.slips.append(slip3.text)
root.slips.append(slip4.text)
root.input_append(root.slips)
print(root.slips)
<DefaultSlips>:
name: "DefaultSlips"
BoxLayout:
orientation: "vertical"
size_hint: 0.75,0.50
pos_hint:{"center_x":0.5,"top":0.75}
Button:
text: "Flowers"
size_hint: 0.4,2.5
pos_hint:{"center_x":0.5}
on_release:
app.root.transition = SlideTransition(direction = 'left')
app.root.current = "PlayScreen"
app.root.Flowerscopy()
当我使用函数Flowerscopy()并尝试更改CustomSlips屏幕的清单列表时,在DefaulSlips屏幕上出现错误。 帮帮我
谢谢