1

I'm fairly new at Kivy, and when I'm importing the kivy.uix.listview module to create a ListItemButton, I'm getting an error that the module is not been found.

Last week I had no issues with this line of code, and so I tried uninstalling and re-installing Kivy with no luck, using:

python -m pip install --upgrade pip wheel setuptools

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew --extra-index-url https://kivy.org/downloads/packages/simple/

python -m pip install kivy

I've been following a tutorial that was helping me, but he doesn't seem to have this issue. Source: http://www.newthinktank.com/2016/10/kivy-tutorial-4/

studentdb.py

# ------ studentdb.py ------
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ObjectProperty
from kivy.uix.listview import ListItemButton


class StudentListButton(ListItemButton):
    pass


class StudentDB(BoxLayout):

    # Connects the value in the TextInput widget to these
    # fields
    first_name_text_input = ObjectProperty()
    last_name_text_input = ObjectProperty()
    student_list = ObjectProperty()

    def submit_student(self):

        # Get the student name from the TextInputs
        student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text

        # Add the student to the ListView
        self.student_list.adapter.data.extend([student_name])

        # Reset the ListView
        self.student_list._trigger_reset_populate()

    def delete_student(self, *args):

        # If a list item is selected
        if self.student_list.adapter.selection:

            # Get the text from the item selected
            selection = self.student_list.adapter.selection[0].text

            # Remove the matching item
            self.student_list.adapter.data.remove(selection)

            # Reset the ListView
            self.student_list._trigger_reset_populate()

    def replace_student(self, *args):

        # If a list item is selected
        if self.student_list.adapter.selection:

            # Get the text from the item selected
            selection = self.student_list.adapter.selection[0].text

            # Remove the matching item
            self.student_list.adapter.data.remove(selection)

            # Get the student name from the TextInputs
            student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text

            # Add the updated data to the list
            self.student_list.adapter.data.extend([student_name])

            # Reset the ListView
            self.student_list._trigger_reset_populate()


class StudentDBApp(App):
    def build(self):
        return StudentDB()


dbApp = StudentDBApp()

dbApp.run()

studentdb.kv

# ------- studentdb.kv -------
StudentDB:

<StudentDB>:
    orientation: "vertical"
    first_name_text_input: first_name
    last_name_text_input: last_name
    student_list: students_list_view
    padding: 10
    spacing: 10

    BoxLayout:
        size_hint_y: None
        height: "40dp"

        Label:
            text: "First Name"
        TextInput:
            id: first_name
        Label:
            text: "Last Name"
        TextInput:
            id: last_name

    BoxLayout:
        size_hint_y: None
        height: "40dp"
        Button:
            text: "Submit"
            size_hint_x: 15
            on_press: root.submit_student()
        Button:
            text: "Delete"
            size_hint_x: 15
            on_press: root.delete_student()
        Button:
            text: "Replace"
            size_hint_x: 15
            on_press: root.replace_student()

    # Define starting data and point to the ListItemButton
    # in the Python code
    ListView:
        id: students_list_view
        adapter:
            ListAdapter(data=["Doug Smith"], cls=main.StudentListButton)

Error - ModuleNotFoundError

# ------ ERROR MESSAGE -----
Traceback (most recent call last):
    File "studentdb.py", line 4, in <module>
    from kivy.uix.listview import ListItemButton
ModuleNotFoundError: No module named 'kivy.uix.listview'
ikolim
  • 15,721
  • 2
  • 19
  • 29
KMO
  • 35
  • 1
  • 5
  • 2
    The `listview` module was deprecated. I don't think it is included in kivy 1.11. What version of kivy are you using? – John Anderson Jun 15 '19 at 23:35
  • 2
    @KMO: Welcome to StackOverflow. You are getting that error because `ListView` is no longer defined in the recently released stable Kivy version 1.11.0. Please refer to an example using [RecycleView in replacement of ListView](https://stackoverflow.com/questions/56601384/kivy-unknown-class-listview-error-code/56601656#56601656). – ikolim Jun 16 '19 at 13:11
  • Thank you so much!! Since I upgraded to version 1.11.0, I will have to use the RecycleView now – KMO Jun 17 '19 at 00:26

1 Answers1

1

The listview module is deprecated. If you want to still use it,

Step 1: Install cython.

pip install Cython==0.29.9

Step 2: Install kivy 1.10.0

pip install kivy==1.10.0
Dev-I-J
  • 49
  • 1
  • 8