Python Forum
[Kivy] Type error:takes 1 positional argument but 2 required
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] Type error:takes 1 positional argument but 2 required
#1
From what i found online, below error should be satisfied if the called method has self included as an argument. To me it appears i have that part satisfied but i still get the error. calling the on_button method from btnAccept.bind(on_press=self.on_button)

Error:
Exception has occurred: TypeError (note: full exception trace is shown but execution is paused at: <module>) on_button() takes 1 positional argument but 2 were given File "/home/mark/Python Environments/FirstEnvProject/ClassTest6.py", line 107, in <module> (Current frame) CreateApp().run()
class MyApp(TabbedPanel):
    def __init__(self,data_base):
        super(MyApp, self).__init__()
      ...
            if str(i)=='Add':
                myTPHM.content=self.enterScreen()
        
       

    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))
        ...
        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=''
        
...
Reply
#2
In your previous thread, in my post https://python-forum.io/thread-35460-pos...#pid149514 I assumed that a button event passes no attributes but obviously, it does.

The docs show a value parameter https://kivy.org/doc/stable/api-kivy.uix.button.html
Reply
#3
Resolved! def on_button(self,instance): worked. Thanks again for the direction. Honestly, I did not think to search for this error resolution in Kivy. I will try to broaden my searches.
Reply
#4
Whenever I write a callback function and I am not positive about the arguments I start with this:
def callback_function(*args, **kwargs):
    print(args, kwargs)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax Error: Positional argument follows keyword argument Rama02 3 4,133 Feb-09-2021, 06:10 PM
Last Post: deanhystad
  [Tkinter] Button command getting TypeError: radsa() missing 3 required positional arguments nonzzo 2 3,388 Apr-22-2019, 12:36 PM
Last Post: Larz60+
  Error TypeError: KeyboardSwitch() missing 8 required positional arguments: 'msg', 'vk Camember_beret_baguette 1 3,826 Dec-11-2018, 08:09 PM
Last Post: Larz60+
  Qt and QtPy Edit window & argument 1 has unexpected type 'Ui_MainWindow' Error Athul 6 21,231 Aug-20-2018, 02:09 PM
Last Post: Axel_Erfurt
  [Tkinter] Takes 1 Positional Argument but 2 were Given Anysja 2 50,262 Aug-08-2018, 07:08 PM
Last Post: Anysja
  [Kivy] Error:__init__ takes no parameters antonmichel 2 3,932 Feb-12-2018, 08:27 PM
Last Post: antonmichel

Forum Jump:

User Panel Messages

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