Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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)
share|improve this question

2 Answers 2

up vote 2 down vote accepted

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

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

share|improve this answer

I guess what you could do is

  1. supply a custom widget for your notebook tab labels via set_tab_label
  2. use set_size_request to set label widget's size

See if an example below would work for you:

import gtk
import sys;

class TestNotebook(gtk.Notebook):
    def __init__(self):
        gtk.Notebook.__init__(self)

    def add_new_tab(self, icon):
        image = gtk.Image()
        image.set_from_stock(icon, gtk.ICON_SIZE_DIALOG)
        image.show_all()        

        tab_image = gtk.Image()
        tab_image.set_from_stock(icon, gtk.ICON_SIZE_MENU)

        box = gtk.HBox()
        box.pack_start(tab_image, False, False)
        box.pack_start(gtk.Label(icon), True, True)
        # set tab size here
        box.set_size_request(50, 50)        
        box.show_all()

        self.set_current_page(self.append_page(image))
        self.set_tab_label(image, box)

if __name__ == '__main__':
    notebook = TestNotebook()
    notebook.add_new_tab(gtk.STOCK_ABOUT)
    notebook.add_new_tab(gtk.STOCK_ADD)
    notebook.add_new_tab(gtk.STOCK_APPLY)

    box = gtk.VBox()
    box.pack_start(notebook)

    window = gtk.Window()
    window.resize(600, 400)
    window.add(box)
    window.show_all()

    gtk.main()
    sys.exit(0)

hope this helps, regards

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["                  <li><a href=\"//area51.stackexchange.com\" title=\"proposing new sites in the Stack Exchange network\">Area 51</a></li>\r\n                        <li><a href=\"//careers.stackoverflow.com\">Stack Overflow Careers</a></li>\r\n                    \r\n                </ol>\r\n            </td>\r\n    </tr>\r\n</table>\r\n                </div>\r\n            </div>\r\n\r\n            <div id=\"copyright\">\r\n                site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href=\"http://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a> \r\n                with <a href=\"http://blog.stackoverflow.com/2009/06/attribution-required/\" rel=\"license\">attribution required</a>\r\n            </div>\r\n            <div id=\"svnrev\">\r\n                rev 2015.5.1.2550\r\n            </div>\r\n            \r\n        </div>\r\n    </div>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works best with JavaScript enabled<img src=\"http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif\" alt=\"\" class=\"dno\"></div>\r\n    </nosc"], "copyright__copyright__copyright": ["ook.add_new_tab(gtk.STOCK_ADD)\n    notebook.add_new_tab(gtk.STOCK_APPLY)\n\n    box = gtk.VBox()\n    box.pack_start(notebook)\n\n    window = gtk.Window()\n    window.resize(600, 400)\n    window.add(box)\n    window.show_all()\n\n    gtk.main()\n    sys.exit(0)\n\nhope this helps, regards\n\nshare|improve this answer\n\nYour Answer\n\n\u00a0\ndiscard\n\nBy posting your answer, you agree to the privacy policy and terms of service.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}