missing one required positional argument error

22 views
Skip to first unread message

M H

unread,
Nov 20, 2025, 3:53:33 PMNov 20
to Kivy users support
Greetings. I've been trying to make a basic checklist app with Kivy. However, I have been unable to get the new line function to work without getting an error which I assume has to do with arguments or something. I will share some of my code below. Please help out if you can.

class Shopping_List(BoxLayout):
     
    def __init__(self, **kwargs):
        super(Shopping_List, self).__init__(**kwargs)

        self.orientation='vertical'
        global list_page
        list_page = GridLayout(cols=1, spacing=1, size_hint_y = None)
        list_page.bind(minimum_height=list_page.setter('height'))

        scroll = ScrollView()

        list_page.add_widget(Check_list_item())

        scroll.add_widget(list_page)
        self.add_widget(scroll) #pages for shopping lists

    def new_line(self, instance):
            item = Check_list_item(self)
            list_page.add_widget(item)

           




class Check_list_item(BoxLayout):
    def __init__(self,**kwargs):
        super(Check_list_item).__init__(**kwargs)
        self.orientation='horizontal'
        self.c_box=CheckBox(size_hint_x = None, size_hint_y=None, height = dp(25), width = dp(20))
        self.text_line=TextInput(multiline=False, font_size= sp(13), text='', size_hint_x = 1, size_hint_y=None, height = dp(25))
        self.text_line.bind(on_text_validate=Shopping_List.new_line(self))
        self.c_button=Button(text='X', size_hint_y=None, size_hint_x=None, height = dp(25), width = dp(25))

        self.add_widget(self.c_box)
        self.add_widget(self.text_line)
        self.add_widget(self.c_button)

ElliotG

unread,
Nov 20, 2025, 4:15:19 PMNov 20
to Kivy users support
Please share a complete runnable example.  It will make it easier to find the problem.

ElliotG

unread,
Nov 20, 2025, 5:10:56 PMNov 20
to Kivy users support
Looking at your code I can see at least one issue:

self.text_line.bind(on_text_validate=Shopping_List.new_line(self))
You want to bind to the instance of ShoppingList, not the class definition. There is an important difference between the class definition,
and the instance of a class.

I put together a small example using your code as a starting point. I hope this helps.
I use kv, because I find it much faster for putting together layouts. I think you can see how the ShoppingList and Item, are similar to your code. The id/ids mechanism in kivy provide a way to access widgets in the widget tree. When the kv is processed, each kv rule gets it's own
ids dictionary that associates the id (the key) with the widget (the value in the ids dict).

Notice how the in ShoppingList.new_item(), the ids is used to add the item to the layout under the ScrollView.
In the kv code you can see how the ids is used to call the new_item method.
app.root.ids.shopping_list.new_item()
app is the app
root is the root widget of the app, here a BoxLayout
ids is the ids dict under the root widget
shoppint_list is the id that refers to the ShoppingList instance.

Here is the code. This is a complete runnable example. I hope this helps. Reach out if you have any questions.

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty

kv = """
<ShoppingList>: # BoxLayout
    orientation: 'vertical'
    ScrollView:
        do_scroll_y: True
        do_scroll_x: False
        BoxLayout:
            id: sl_content
            orientation: 'vertical'
            size_hint_y: None
            height: self.minimum_height
            Item:
                text: 'New Item'

<Item>: # BoxLayout
    size_hint_y: None
    height: '48dp'
    CheckBox:
        size_hint_x: None
        width: '20dp'
    TextInput:
        id: text_input
        multiline: False
        write_tab: False
        on_text_validate: app.root.ids.shopping_list.new_item()
        padding: '14sp'
        text: root.text
    Button:
        size_hint_x: None
        width: '40dp'
        text: 'X'
        on_release: root.parent.remove_widget(root)
       

BoxLayout:  # instance the root widget
    orientation: 'vertical'
    Label:
        size_hint_y: None
        height: '30dp'
        text: 'Shopping List App'
    ShoppingList:
        id: shopping_list
"""


class ShoppingList(BoxLayout):
    def new_item(self):
        item = Item()
        self.ids.sl_content.add_widget(item)
        item.ids.text_input.focus = True


class Item(BoxLayout):
    text = StringProperty()


class ShoppingListApp(App):
    def build(self):
        return Builder.load_string(kv)

ShoppingListApp().run()
Reply all
Reply to author
Forward
0 new messages