File: colorbutton.py

package info (click to toggle)
python-gtk2-tutorial 2.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,376 kB
  • ctags: 918
  • sloc: python: 5,731; makefile: 36
file content (37 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class 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
        return

def main():
    gtk.main()


if __name__ == '__main__':
    cbe = ColorButtonExample()
    main()