Nov-05-2021, 03:07 PM
Can you pass arguments in the kivy bind operation? See below where i am experimenting with calling a function to build a input screen and add it to a tabbed header. Also on the bind operation I try to pass the text input widget so i can also clear it's text in the on_pressed event. The issue is the on_pressed event is called as the code is executed adding empty data to my table without the btnAccept being pressed.
Also, if i did not post code correctly let me know-thanks
Also, if i did not post code correctly let me know-thanks
con=sqlite3.connect('bovine.db'); c=con.cursor(); #c.execute(""" CREATE TABLE cattleData # (tagNo integer, # Loc text, # sex text, # type text) # """) #c.execute(""" CREATE TABLE locations # (Hermas text, # Tobaco Barn text, # Chambers text, # New Barn) # """) locList=["Hermas","Tobbaco Barn","New Barn","Chambers"] opList=["Location","Add","Edit"] class myTabbedPanel(TabbedPanel): def __init__(self): super(myTabbedPanel, self).__init__() self.do_default_tab=False for i in opList: myTPHM=TabbedPanelHeader() myTPHM.text=str(i) self.add_widget(myTPHM) if str(i)=='Location': myTPLoc=TabbedPanel() myTPLoc.do_default_tab=False myTPHM.content=myTPLoc for j in locList: myTPHL=TabbedPanelHeader() myTPHL.text=str(j) myTPLoc.add_widget(myTPHL) if str(i)=='Add': myTPHM.content=myTabbedPanel.enterScreen() def enterScreen(): stkEnter=StackLayout(orientation='lr-tb',spacing=4) lbl1=Label(text='Tag No',size_hint=(.1,.04)) lbl2=Label(text='Location',size_hint=(.1,.04)) lbl3=Label(text='Sex',size_hint=(.1,.04)) lbl4=Label(text='type',size_hint=(.1,.04)) txtTag=TextInput(text='',size_hint=(.1,.06)) txtLoc=TextInput(text='',size_hint=(.1,.06)) txtSex=TextInput(text='',size_hint=(.1,.06)) txtType=TextInput(text='',size_hint=(.1,.06)) btnAccept=Button(text='add',size_hint=(.1,.04)) stkEnter.add_widget(lbl1) stkEnter.add_widget(txtTag) stkEnter.add_widget(lbl2) stkEnter.add_widget(txtLoc) stkEnter.add_widget(lbl3) stkEnter.add_widget(txtSex) stkEnter.add_widget(lbl4) stkEnter.add_widget(txtType) stkEnter.add_widget(btnAccept) btnAccept.bind(on_press=pressed(txtTag,txtLoc,txtSex,txtType)) # **** Here **** return stkEnter def pressed(txtTag,txtLoc,txtSex,txtType): c.execute("INSERT INTO cattleData VALUES(?,?,?,?)",(txtTag.text,txtLoc.text,txtSex.text,txtType.text)) con.commit() txtTag.text='' txtLoc.text='' txtSex.text='' txtType.text=''