buttonbox.py

来自「使用Pygtk写的几个例子」· Python 代码 · 共 89 行

PY
89
字号
#!/usr/bin/env python'''Button BoxThis demo shows various button box configurations available.  It alsouses stock buttons, and use of mnemonics for navigation.'''import gtkdef create_bbox(horizontal=True, title=None, spacing=0,        layout=gtk.BUTTONBOX_SPREAD):    frame = gtk.Frame(title)    if horizontal:        bbox = gtk.HButtonBox()    else:        bbox = gtk.VButtonBox()    bbox.set_border_width(5)    bbox.set_layout(layout)    bbox.set_spacing(spacing)    frame.add(bbox)    button = gtk.Button(stock='gtk-ok')    bbox.add(button)    button = gtk.Button(stock='gtk-cancel')    bbox.add(button)    button = gtk.Button(stock='gtk-help')    bbox.add(button)    return frameclass ButtonBoxDemo(gtk.Window):    def __init__(self, parent=None):        # Create the toplevel window        gtk.Window.__init__(self)        try:            self.set_screen(parent.get_screen())        except AttributeError:            self.connect('destroy', lambda *w: gtk.main_quit())        self.set_title(self.__class__.__name__)        self.set_border_width(10)        main_vbox = gtk.VBox()        self.add(main_vbox)        frame_horiz = gtk.Frame("Horizontal Button Boxes")        main_vbox.pack_start(frame_horiz, padding=10)        vbox = gtk.VBox()        vbox.set_border_width(10)        frame_horiz.add(vbox)        vbox.pack_start(create_bbox(True, "Spread", 40, gtk.BUTTONBOX_SPREAD),                padding=0)        vbox.pack_start(create_bbox(True, "Edge", 40, gtk.BUTTONBOX_EDGE),                padding=5)        vbox.pack_start(create_bbox(True, "Start", 40, gtk.BUTTONBOX_START),                padding=5)        vbox.pack_start(create_bbox(True, "End", 40, gtk.BUTTONBOX_END),                padding=5)        frame_vert = gtk.Frame("Vertical Button Boxes")        main_vbox.pack_start(frame_vert, padding=10)        hbox = gtk.HBox()        hbox.set_border_width(10)        frame_vert.add(hbox)        hbox.pack_start(create_bbox(False, "Spread", 40, gtk.BUTTONBOX_SPREAD),                padding=0)        hbox.pack_start(create_bbox(False, "Edge", 40, gtk.BUTTONBOX_EDGE),                padding=5)        hbox.pack_start(create_bbox(False, "Start", 40, gtk.BUTTONBOX_START),                padding=5)        hbox.pack_start(create_bbox(False, "End", 40, gtk.BUTTONBOX_END),                padding=5)        self.show_all()def main():    ButtonBoxDemo()    gtk.main()if __name__ == '__main__':    main()

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?