我正在尝试在 Accordion 中使用 PageLayout,但是当我尝试单击任何位置时,它给了我这个错误。如何使它工作。
Traceback (most recent call last):
File "accmain.py", line 19, in <module>
LiuApp().run()
File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 828, in run
runTouchApp()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 487, in runTouchApp
EventLoop.window.mainloop()
File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_sdl2.py", line 619, in mainloop
self._mainloop()
File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_sdl2.py", line 362, in _mainloop
EventLoop.idle()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 330, in idle
self.dispatch_input()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 315, in dispatch_input
post_dispatch_input(*pop(0))
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 221, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 1034, in on_motion
self.dispatch('on_touch_up', me)
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 1070, in on_touch_up
if w.dispatch('on_touch_up', touch):
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 454, in on_touch_up
if child.dispatch('on_touch_up', touch):
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 454, in on_touch_up
if child.dispatch('on_touch_up', touch):
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 454, in on_touch_up
if child.dispatch('on_touch_up', touch):
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 454, in on_touch_up
if child.dispatch('on_touch_up', touch):
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 454, in on_touch_up
if child.dispatch('on_touch_up', touch):
File "_event.pyx", line 718, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:7146)
File "/usr/lib/python2.7/dist-packages/kivy/uix/pagelayout.py", line 201, in on_touch_up
return self.children[-self.page + 1].on_touch_up(touch)
IndexError: list index out of range
到目前为止,这是我为解决此错误所做的工作。 accmain.py 文件
from kivy.app import App
from kivy.uix.accordion import Accordion
class RunLiu(Accordion):
def __init__(self, **kwargs):
super(RunLiu, self).__init__(**kwargs)
class LiuApp(App):
def build(self):
root = RunLiu()
return root
if __name__ == "__main__":
LiuApp().run()`
liu.kv 文件
<RunLiu>:
orientation: "vertical"
AccordionItem:
title: "Item 1"
PageLayout:
Label:
text: "yee"
AccordionItem:
title: "Item 2"
Label:
text: "hey there"
AccordionItem:
title: "3rd tab"
Label:
text: 'Item 3'
抱歉格式化,我对堆栈溢出和 kivy 都很陌生。我的文件中的所有缩进都是正确的。