-
I have a container in which I want to set completely different widgets reactively. I've been doing: def watch_blah(self, new_value: str) -> None:
for child in self.children:
child.remove()
# self.mount(*widgets) based on new_value This works, but I've noticed that it can be a bit slow to remove for more than five or so children. I'm guessing this is because it redraws for every child? Is there a better way to do this? Having a |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
One way to do this would be to use the child combinator to get a query of all the children of a particular node, then use the However... internally it does more or less what you're doing right now and has the same performance hit. I don't think it's been raised as a particular issue just yet, but @willmcgugan has identified that In short: personally I think |
Beta Was this translation helpful? Give feedback.
One way to do this would be to use the child combinator to get a query of all the children of a particular node, then use the
remove
loop-free operation with that query.However... internally it does more or less what you're doing right now and has the same performance hit. I don't think it's been raised as a particular issue just yet, but @willmcgugan has identified that
remove
on a query needs some work to make it faster (this came about last weekend when I ran into the same thing as you, only using what I'm suggesting here, to remove 1,600 widgets in one go).In short: personally I think
remove
on a query is the way to go and the speed should then improve in a future release of Textual.