【发布时间】:2019-12-03 15:23:12
【问题描述】:
Python 代码:
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.screenmanager import ScreenManager,Screen,FadeTransition
from kivy.app import App
import copy
class introscreen(ScreenManager,Screen):
pass
class screenone(Screen):
pass
class screentwo(Screen):
slips = []
def Flowerscopy(self):
Flower = ["Rose", "Tulips", "Sunflower", "Marigold"]
slips = copy.copy(Flower)
class testApp(App):
SO = screenone()
ST = screentwo()
def build(self):
return introscreen()
if __name__ == "__main__":
testApp().run()
.kv 代码
<introscreen>:
#: import SlideTransition kivy.uix.screenmanager.SlideTransition
transition: SlideTransition()
screenone:
screentwo:
<screenone>:
name: "One"
FloatLayout:
BoxLayout:
orientation: "vertical"
size_hint: 0.50,0.50
pos_hint:{"center_x":0.5,"top":0.75}
Button:
text: "Flowers"
size_hint: 0.5,2.5
pos_hint:{"center_x":0.5}
on_release:
app.root.transition = SlideTransition(direction = 'left')
app.root.current = "Two"
app.ST.Flowerscopy()
<screentwo>:
name: "Two"
BoxLayout:
orientation : "horizontal"
pos_hint : {"center_x": 0.2,"top": 0.2}
size_hint: 0.80,0.30
Label:
id: s1
text: str(root.slips[0])
我正在练习我的 kivy 基础知识。我遇到了一个错误问题,即索引超出范围错误 当我尝试在 class screentwo 中的 slips list 的标签上放置文本并且我想使用Flowerscopy() 在第一个屏幕调用并且还想在标签上打印,因为单据是空的,他们给我错误请帮助我,我现在是初学者
【问题讨论】:
标签: python python-3.x kivy kivy-language