Nov-07-2021, 10:31 PM
After attempting to model after above suggestions , the MyDataBase class seems to work well, however; the error below of not recognizing myTPHM has me stumped as the deBug console agrees it is a TabbedPanelHeader widget.
Also can you clarify the need for the __init__ in the MyApp class?
I understand I have to Run the sub-classed App of Kivy and is it OK to add the the data_base and TabbedPannel as arguments in the __init__ method?
Also can you clarify the need for the __init__ in the MyApp class?
I understand I have to Run the sub-classed App of Kivy and is it OK to add the the data_base and TabbedPannel as arguments in the __init__ method?
Error:Exception has occurred: TypeError
add_widget() missing 1 required positional argument: 'widget'
File "/home/mark/Python Environments/FirstEnvProject/ClassTest6.py", line 52, in __init__
self.root_widget.add_widget(self.myTPHM)
File "/home/mark/Python Environments/FirstEnvProject/ClassTest6.py", line 103, in main
MyApp(my_db,TabbedPanel).run()
File "/home/mark/Python Environments/FirstEnvProject/ClassTest6.py", line 107, in <module>
main()
from sqlite3 import dbapi2 import kivy from kivy.uix.tabbedpanel import TabbedPanel from kivy.app import App from kivy.uix.tabbedpanel import TabbedPanelHeader from kivy.uix.button import Button from kivy.uix.stacklayout import StackLayout from kivy.uix.label import Label from kivy.uix.textinput import TextInput import sqlite3 #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 MyDataBase: def __init__(self,db_path): self.db_path=db_path def connect(self): self.con=sqlite3.connect(self.db_path) self.c=self.con.cursor() def insert_cattledata(self,tag,loc,sex,type_): self.cur.execute("INSERT INTO cattleData VALUES(?,?,?,?)",(tag,loc,sex,type_)) self.con.commit() class MyApp(App): def __init__(self,data_base,TabbedPanel): self.db=data_base self.root_widget=TabbedPanel self.root_widget.do_default_tab=False for i in opList: myTPHM=TabbedPanelHeader() myTPHM.text=str(i) self.root_widget.add_widget(myTPHM) if str(i)=='Location': myTPLoc=TabbedPanel() myTPLoc.do_default_tab=False self.myTPHM.content=myTPLoc for j in locList: myTPHL=TabbedPanelHeader() myTPHL.text=str(j) myTPLoc.add_widget(myTPHL) if str(i)=='Add': myTPHM.content=self.enterScreen() return self.root_widget def enterScreen(self): 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)) self.txtTag=TextInput(text='',size_hint=(.1,.06)) self.txtLoc=TextInput(text='',size_hint=(.1,.06)) self.txtSex=TextInput(text='',size_hint=(.1,.06)) self.txtType=TextInput(text='',size_hint=(.1,.06)) btnAccept=Button(text='add',size_hint=(.1,.04)) stkEnter.add_widget(lbl1) stkEnter.add_widget(self.txtTag) stkEnter.add_widget(lbl2) stkEnter.add_widget(self.txtLoc) stkEnter.add_widget(lbl3) stkEnter.add_widget(self.txtSex) stkEnter.add_widget(lbl4) stkEnter.add_widget(self.txtType) stkEnter.add_widget(btnAccept) btnAccept.bind(on_press=self.on_button) return stkEnter def on_button(self): self.db.insert_cattledata(self.txtTag.text,self.txtLoc.text,self.txtSex.text,self.txtType.text) self.txtTag.text='' self.txtLoc.text='' self.txtSex.text='' self.txtType.text='' def main(): my_db=MyDataBase('bovine.db') my_db.connect() MyApp(my_db,TabbedPanel).run() if __name__ == '__main__': main()