[pygtk] adding a close button to a notebook
mithrandir42 at web.de
Sun Oct 22 16:45:26 WST 2006
Tony Nelson schrieb:
> At 8:36 AM +0200 10/20/06, N. Volbers wrote:
>> Hello everyone,
>> I am using a notebook for a sort of tabbed interface a la Firefox.
>> Currently, there is a close button for each tab, positioned in the tab
>> widget. However, I would like to have just a single close button at the
>> very right of the notebook (again, just like Firefox does). Is there a
>> way to add a widget inside the notebook tab box?
> I use something like this:
> class NotebookTabLabel(gtk.HBox):
> '''Notebook tab label with close button.
> def __init__(self, on_close, owner_):
> gtk.HBox.__init__(self, False, 0)
> label = self.label = gtk.Label()
> label.set_alignment(0.0, 0.5)
> close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
> image_w, image_h = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)
> close_btn = gtk.Button()
> close_btn.connect('clicked', on_close, owner_)
> close_btn.set_size_request(image_w+2, image_h+2)
> self.pack_start(close_btn, False, False)
> tl = NotebookTabLabel(
> lambda *args: self.owner.on_tab_close_doc(*args),
> self )
> I hacked this down from something fancier, but I think it's still all there.
Thanks for your reply!
The example you provide is very useful, even though it is not exactly
what I had in mind. I was looking for a single close button that belongs
to the notebook, and not a button for each tab. Yet your solution works
well for me, so unless someone suggests something different, I will use
More information about the pygtk