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

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=''
Yoriz write Nov-05-2021, 03:50 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
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,315 Jun-30-2022, 08:17 PM
Last Post: deanhystad
  [Tkinter] binding versus disable DPaul 6 7,149 May-05-2021, 05:17 PM
Last Post: DPaul
  [Tkinter] Binding Entry box to <Button-3> created in for loop iconit 5 5,238 Apr-22-2020, 05:47 AM
Last Post: iconit
  TkInter Binding Buttons ifigazsi 5 5,036 Apr-06-2020, 08:30 AM
Last Post: ifigazsi
  Making text clickable with binding DT2000 10 5,461 Apr-02-2020, 10:11 PM
Last Post: DT2000
  [Tkinter] Setting Binding to Entry created with a loop? p_hobbs 1 2,152 Nov-25-2019, 10:29 AM
Last Post: Larz60+
  Binding functions in Qt Designerr Mocap 12 6,233 Aug-22-2019, 03:38 PM
Last Post: Denni
  Binding functions to Menus in tkinter?? Mocap 1 2,534 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,240 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