更改ttkbootstrap ScrolledFrame的内容

huangapple go评论94阅读模式
英文:

Change the content of a ttkbootstrap ScrolledFrame

问题

我如何替换ttkbootstrap ScrolledFrame的内容?

我已经使用以下代码创建了滚动帧:

        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")

基于按钮点击,我需要清空ScrolledFrame并用不同的内容替换它。

如何实现这一目标?

英文:

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?

答案1

得分: 0

我发现我需要一个单独的内容列表,然后才能对其进行遍历以进行销毁。

代码段现在如下:

        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")

其中 tw 包含新的推文列表。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 23:03:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663669.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定