0

How do I replace the content of a ttkbootstrap ScrolledFrame?

I have built the scrolled frame with this snippet:

        for ndx, t in enumerate(sorted(tw, key=lambda x: x.created_at, reverse=True)):
            print(t.created_at)
            card = make_tweet_card(t, tweet_detail_scroller)
            card.grid(pady=5, row=ndx, column=0, sticky="W")

Based on a button click I need to empty the ScrolledFrame and replace the content with different content.

How can I achieve this?

user2302244
  • 843
  • 2
  • 11
  • 27

1 Answers1

0

I found that I needed a separate list of the content before I could iterate through it for destruction.

The snippet is now:

        if len(tweet_detail_scroller.children) > 0:
            content = [cw for cw in tweet_detail_scroller.children.values()]
            for cw in content:
                cw.destroy()
        for ndx, t in enumerate(sorted(tw, key=lambda x: x.created_at, reverse=True)):
            print(t.created_at)
            card = make_tweet_card(t, tweet_detail_scroller)
            card.grid(pady=5, row=ndx, column=0, sticky="W")

where tw contains the new list of tweets.

user2302244
  • 843
  • 2
  • 11
  • 27