Python Forum
kivy binding issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
kivy binding issue
#7
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?

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()
Reply


Messages In This Thread
kivy binding issue - by hammer - Nov-05-2021, 03:07 PM
RE: kivy binding issue - by Yoriz - Nov-05-2021, 04:00 PM
RE: kivy binding issue - by hammer - Nov-06-2021, 02:15 AM
RE: kivy binding issue - by Yoriz - Nov-06-2021, 10:51 AM
RE: kivy binding issue - by hammer - Nov-06-2021, 01:26 PM
RE: kivy binding issue - by Yoriz - Nov-06-2021, 03:34 PM
RE: kivy binding issue - by hammer - Nov-07-2021, 10:31 PM
RE: kivy binding issue - by Yoriz - Nov-07-2021, 11:14 PM
RE: kivy binding issue - by hammer - Nov-07-2021, 11:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Key Binding scope angus1964 1 1,264 Jun-30-2022, 08:17 PM
Last Post: deanhystad
  [Tkinter] binding versus disable DPaul 6 6,968 May-05-2021, 05:17 PM
Last Post: DPaul
  [Tkinter] Binding Entry box to <Button-3> created in for loop iconit 5 5,082 Apr-22-2020, 05:47 AM
Last Post: iconit
  TkInter Binding Buttons ifigazsi 5 4,728 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Making text clickable with binding DT2000 10 5,306 Apr-02-2020, 10:11 PM
Last Post: DT2000
  [Tkinter] Setting Binding to Entry created with a loop? p_hobbs 1 2,108 Nov-25-2019, 10:29 AM
Last Post: Larz60+
  Binding functions in Qt Designerr Mocap 12 6,042 Aug-22-2019, 03:38 PM
Last Post: Denni
  Binding functions to Menus in tkinter?? Mocap 1 2,493 Jul-23-2019, 01:37 AM
Last Post: Larz60+
  [Kivy] Kivy property (in .kv) loses binding to a variable (in .py) j.crater 3 5,187 Aug-14-2018, 12:37 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020