[pygtk] Re: howto create border around widget?

skip at pobox.com skip at pobox.com
Mon Oct 15 21:22:48 WST 2007


    Michael> IMO. For example it looks [GtkFrame] will never allow me to
    Michael> have, say, 2px-wide red border around a widget with 0px
    Michael> distance between the widget and the border.

Here's a way to do it using gtk.Frame:

    import gtk

    def exit(*args):
        raise SystemExit

    def main():
        w = gtk.Window()
        w.connect("destroy", exit)
        f = gtk.Frame()
        b = gtk.Button("Hello World!")
        b.connect("clicked", exit)
        f.set_border_width(2)
        f.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(65535))
        f.add(b)
        w.add(f)
        w.show_all()
        gtk.main()

    if __name__ == "__main__":
        main()

Certainly not the most elegant thing, but it seems to work for the most
part.  I'm sure you can improve it.

Skip


More information about the pygtk mailing list