![]() |
[Kivy] Type error:takes 1 positional argument but 2 required - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Kivy] Type error:takes 1 positional argument but 2 required (/thread-35489.html) |
Type error:takes 1 positional argument but 2 required - hammer - Nov-08-2021 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)
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='' ... RE: Type error:takes 1 positional argument but 2 required - Yoriz - Nov-09-2021 In your previous thread, in my post https://python-forum.io/thread-35460-post-149514.html#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 RE: Type error:takes 1 positional argument but 2 required - hammer - Nov-09-2021 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. RE: Type error:takes 1 positional argument but 2 required - deanhystad - Nov-09-2021 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) |