colorbutton.py

来自「pygtk的教程」· Python 代码 · 共 38 行

PY
38
字号
#!/usr/bin/env pythonimport pygtkpygtk.require('2.0')import gtkclass ColorButtonExample:    def __init__(self):        window = gtk.Window()        window.connect('destroy', lambda w: gtk.main_quit())        hbox = gtk.HBox()        window.add(hbox)        label = gtk.Label('Foreground Color:')        hbox.pack_start(label, False)        colorbutton = gtk.ColorButton(gtk.gdk.color_parse('red'))        colorbutton.set_use_alpha(True)        colorbutton.set_title('Select a Color')        colorbutton.set_alpha(32767)        colorbutton.connect('color-set', self.color_set_cb)        hbox.pack_start(colorbutton)        window.show_all()        return    def color_set_cb(self, colorbutton):        color = colorbutton.get_color()        alpha = colorbutton.get_alpha()        print 'You have selected the color:', \              color.red, color.green, color.blue, 'with alpha:', alpha        returndef main():    gtk.main()if __name__ == '__main__':    cbe = ColorButtonExample()    main()

⌨️ 快捷键说明

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