Search code examples
pythonuser-interfacegtkpygtk

Gtk Notebook tab size


I am using a gtkNotebook to show a number of widgets on the bottom of my app. The problem is that when the tabs are showing they take up a lot of space and look awkward in general. I figured out that it is cause by the gtk.ICON_SIZE_MENU being bigger that the text, but I can't find any constants that are smaller and I don't want to give it a exact pixel size since it may mess up on different screen resolutions. Is the any way to get the button to always scalse to the size of the text on the label next to it?

Here is the code that generates the button (the hbox it's in is the widget that the tab displays):

    box = gtk.HBox(False,0)
    btn = gtk.Button()
    image = gtk.Image()
    image.set_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
    btn.set_image(image)
    btn.set_relief(gtk.RELIEF_NONE)
    btn.show()

    if type(label) != type(gtk.Label()):
        label = gtk.Label('Untitled')
    box.pack_start(label)
    box.pack_end(btn)

Solution

  • If you just want to make the Close buttons smaller, have a look at how—for example—Epiphany removes most of the padding around the button.

    Result:

    Tabs in Epiphany, from http://projects.gnome.org/epiphany/images/customizable.png

    (This is a slightly older version of their code; Ephy trunk uses the GTK+ 3.0 CSS styling, but same idea.)