在Kivy中,有没有办法逐个浏览列表或数组的项目。我可以遍历列表,但我希望每个项目只在单击按钮后显示。我需要这个,因为我想为我的用户页面创建个人资料页面,但只有一次点击一个按钮才能看到它们
这是一个小例子:
from kivy.uix.listview import ListView
from kivy.base import runTouchApp
from kivy.uix.button import Button
mylist = ['text1', 'text2', 'text3', 'text4']
def myfunction(self):
print('some function logic needs to go here to display one item upon clicking the button')
class MainView(ListView):
def __init__(self, **kwargs):
super(MainView, self).__init__(
item_strings=[str(x) for x in mylist])
self.add_widget(Button(text='press', size_hint=(1, .05), on_press=myfunction))
runTouchApp(MainView())
# in pure python, i just want to display the following items one by one upon clicking the button
mylist = ['text1', 'text2', 'text3', 'text4']
i = 0
for x in mylist:
print(mylist[i])
i += 1