对list_simple_in_kv.py进行一些改动,以使用ListAdapter代替SimpleListAdapter,我发现方法1起作用:
from kivy.uix.modalview import ModalView
from kivy.uix.listview import ListView
from kivy.uix.gridlayout import GridLayout
from kivy.lang import Builder
from kivy.app import App
#using 'sla'...whatever that means...
Builder.load_string("""
#:import ListItemButton kivy.uix.listview
#:import sla kivy.adapters.listadapter
<ListViewModal>:
ListView:
size_hint: .8, .8
adapter:
sla.ListAdapter(
data=["Item #{0}".format(i) for i in range(100)],
cls=ListItemButton.ListItemButton)
""")
class ListViewModal(ModalView):
def __init__(self, **kwargs):
super(ListViewModal, self).__init__(**kwargs)
class MainView(GridLayout):
def __init__(self, **kwargs):
kwargs['cols'] = 1
super(MainView, self).__init__(**kwargs)
listview_modal = ListViewModal()
self.add_widget(listview_modal)
class TestApp(App):
def build(self):
root = MainView()
return root
if __name__ == '__main__':
TestApp().run()
但是将kv文件更改为这种方式(与我遇到的其他kv API最一致的方式)失败:
Builder.load_string("""
#:import ListItemButton kivy.uix.listview
#:import ListAdapter kivy.adapters.listadapter
<ListViewModal>:
size_hint: None, None
size: 400, 400
ListView:
size_hint: .8, .8
ListAdapter:
data: ["Item #{0}".format(i) for i in range(100)]
cls: ListItemButton.ListItemButton
""")
我什至碰到了这篇文章,这篇文章也是如此,说方法2应该可以在master上工作,但是它却产生了一个异常:
File "C:\Python27\lib\site-packages\kivy\adapters\adapter.py", line 102, in __init__
raise Exception('adapter: input must include data argument')
Exception: adapter: input must include data argument
我在这里想念什么?
MMMHUHU
红糖糍粑
相关分类