[pygtk] adding a close button to a notebook

Tony Nelson tonynelson at georgeanelson.com
Fri Oct 20 21:28:33 WST 2006

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.
TonyN.:'    The Great Writ     <mailto:tonynelson at georgeanelson.com>
      '      is no more.             <http://www.georgeanelson.com/>

More information about the pygtk mailing list