0

Ok so I have read Kivy - Removing widget by id which is almost exactly what I am trying to do, but the answer has been marked correct and does not work. I have tried— many times.

What I want to do is be able to remove each widget when the user clicks unfollow. I am having an issue with the self.ids.widget_list.remove_widget(userRowObj). The print statement outputs:

emmachamberlain <screens.UserRow object at 0x13139F80> got back Removed: <screens.UserRow object at 0x13139F80>

This is correct. It prints the username, then the UserRow object, then the print message identifying it's back to the PurgeScreen class, then the message confirming the removal of the UserRow object, but it is never actually removed from the UI. Important to note the rows are created from py file, but the list (with id widget_list) is created in .kv. Another interesting fact is that "remove_widget" doesn't come up while typing, but "clear_widgets" does and when I tested that one it cleared all the rows from the list in the UI suggesting that it was working. Please help!!! From my screens.py:

class UserRow(GridLayout):
    def __init__(self, obj, profile, user_id, user_name):
        self.calling_obj = obj
        self.profile = profile
        self.user_id = user_id
        self.user_name = user_name

    def create_layout(self):
        layout = GridLayout(rows=1, row_force_default=True, row_default_height=60)
        layout.add_widget(ImageButton(source=self.profile))
        layout.add_widget(Label(text="@" + self.user_name, color=(0, 0, 0, 1), font_size=20))
        layout.add_widget(Label(text=str(self.user_id), color=(0, 0, 0, 0), font_size=20))
        bsplit = GridLayout(rows=1)
        unfollowButton = Button(background_normal='images/buttonbackgrounds/unfollow.png',
                                background_down='images/buttonbackgrounds/unfollow_select.png',
                                size_hint_x=None, width=100)
        unfollowButton.bind(on_release=self.unfollow)
        bsplit.add_widget(unfollowButton)
        bsplit.add_widget(Button(background_normal='images/buttonbackgrounds/waitlist.png',
                                 background_down='images/buttonbackgrounds/waitlist_select.png', size_hint_x=.5,
                                 border=(3, 3, 3, 3)))
        layout.add_widget(bsplit)
        return layout

    def unfollow(self, *args):
        print(self.user_name)
        print(self)
        rt = self.calling_obj
        rt.remove_row(self)




class PurgeScreen(Screen):
    def backButton(self):
        SCREEN_MANAGER.current = 'dashboard'

    def add_row(self, profile, user_id, user_name, percent):
        u = UserRow(self, profile, user_id, user_name)
        l = u.create_layout()
        self.ids.widget_list.add_widget(l)
        self.update_percent(percent)

    def remove_row(self, userRowObj):
        print("got back")
        self.ids.widget_list.remove_widget(userRowObj)
        print("Removed: " + str(userRowObj))
Josh
  • 30
  • 6

0 Answers0