How to delete all widgets inside custom widget and rerender it with new content? #3230
-
Want to delete all the content of TabbedContent and replace it with new one because the data of all tabs will change due to certain action will occur in another event. def unmount_elements(self): self.remove_children() and the other function is responsible to add the content of tabs again, I tried as following: def compose_filtering_users_requests(self): states = self.state_dao.get_states() for index, state in enumerate(states): self.current_state = state tab_pane = self.mount(TabPane(state.get_state(), id=f"state{state.get_id()}")) tab_pane.mount(Label("Test")) this scenario fails because self.mount return AwaitMount but i need the widget itself to add new items to created widget. def compose_filtering_users_requests(self): self.compose() both functions are triggered and called with another class, and it is simplified version from my code any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Might the clear_panes and add_pane methods for TabbedContent help? |
Beta Was this translation helpful? Give feedback.
-
I think it will not work because i am trying to recreate elements like following: def compose(self) -> ComposeResult: states = self.state_dao.get_states() with TabbedContent(): for index, state in enumerate(states): self.current_state = state with TabPane(state.get_state(), id=f"state{state.get_id()}"): with VerticalScroll(id=f"state{state.get_id()}"): yield StateTabContent(self.current_logged_user, state, f"StateTabContent{state.get_id()}") this is the old elements that will be created again with new data |
Beta Was this translation helpful? Give feedback.
-
if i used add_pane , I will face the same problem i am facing with my code add_pane return AwaitMount object not a reference to the tab itself which means i will not be able to add widget to tab itself |
Beta Was this translation helpful? Give feedback.
Might the clear_panes and add_pane methods for TabbedContent help?