我是kivy的新人。
我一遍又一遍地得到这个错误
文件" _event.pyx",第255行,in kivy._event.EventDispatcher.bind(kivy_event.c:3629)
KeyError:' pos_hint'
这是我的代码:
class RiegosBoxLayout(BoxLayout):
def __init__(self, **kwargs):
super(RiegosBoxLayout, self).__init__(**kwargs)
self.orientation= "vertical"
lb= Label(text= "Riegos programados", font_size= '30dp', bold= True, size_hint= (1, .10))
self.add_widget(lb)
db= sqlite3.connect('../db/dbInvernadero.s3db')
cursor = db.cursor()
cursor.execute("select ID, descripcion from tbRiegos")
la= ListAdapter(
data=["{}".format(i[1]) for i in cursor.fetchall()],
selection_mode='single',
allow_empty_selection=False,
cls= ListItemButton)
#lv = ListView( item_strings=[str(i[1]) for i in cursor.fetchall()])
self.add_widget(la) # if i pass lv, it goes ok
db.close()
class MainScreen(Screen):
def __init__(self, **kwargs):
super(MainScreen, self).__init__(**kwargs)
tb_panel= TabbedPanel(do_default_tab=False, size_hint=(1,1), pos_hint= {'center_x': .5, 'center_y': .5})
tabs= ["Operaciones", "Riegos", "Valvulas", "Radiacion", "Configuracion"]
for tb in tabs:
if (tb == "Riegos"):
tbi=TabbedPanelItem(text=tb)
tbi.add_widget(RiegosBoxLayout())
tb_panel.add_widget(tbi)
else:
tb_panel.add_widget(TabbedPanelItem(text=tb))
self.add_widget(tb_panel)
class MainApp(App):
def build(self):
# Create the screen manager
sm = ScreenManager()
sc=MainScreen()
sm.add_widget(sc)
return sm
if __name__ == '__main__':
MainApp().run()
答案 0 :(得分:1)
ListAdapter
不是Widget
。它在您使用ListView
时有效,因为 是Widget
。您需要provide the ListAdapter
to the ListView
:
lv = ListView(adapter=la)
self.add_widget(lv)