在PyGTK / GTK中即时添加/删除笔记本页面

时间:2023-01-24 15:06:30

How to refresh a notebook on the fly?

如何动态刷新笔记本?

I have an application which is supposed to have various number of pages according to the data in the underlying model. In order to synchronize the appearance of the Notebook I'd like to refresh it every time a row is added/deleted from the model.

我有一个应用程序,根据底层模型中的数据,它应该具有不同数量的页面。为了同步笔记本的外观我想每次在模型中添加/删除行时刷新它。

I've tried this:

我试过这个:

    ...
    def get_pagebox(self, label)
        ...
        return pagebox
    def _reinit(self):
        for child in self.notebook.get_children():
            self.notebook.remove(child)
        for label in self.get_labels():
            self.notebook.append(self.get_pagebox(label), label)
        self.notebook.queue_draw_area(0,0,-1,-1)
    ...

It removes the old pages, but fails to append new ones. What could be the problem and how do you think this could be done?

它会删除旧页面,但无法添加新页面。可能是什么问题,您认为如何做到这一点?

2 个解决方案

#1


That looks fine. Did you try doing an explicit show() on the widgets after adding them?

看起来很好。您是否尝试在添加小部件后对小部件执行显式show()?

#2


You should just call show_all() on the notebook after adding the new pages. All widgets created by GTK+ are initially hidden. The queue_draw_area call shouldn't be necessary.

您应该在添加新页面后在笔记本上调用show_all()。最初由GTK +创建的所有小部件都是隐藏的。不需要queue_draw_area调用。

#1


That looks fine. Did you try doing an explicit show() on the widgets after adding them?

看起来很好。您是否尝试在添加小部件后对小部件执行显式show()?

#2


You should just call show_all() on the notebook after adding the new pages. All widgets created by GTK+ are initially hidden. The queue_draw_area call shouldn't be necessary.

您应该在添加新页面后在笔记本上调用show_all()。最初由GTK +创建的所有小部件都是隐藏的。不需要queue_draw_area调用。