File: radiobuttons.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 (74 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python

# example radiobuttons.py

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

class RadioButtons:
    def callback(self, widget, data=None):
        print "%s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()])

    def close_application(self, widget, event, data=None):
        gtk.main_quit()
        return gtk.FALSE

    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  
        self.window.connect("delete_event", self.close_application)

        self.window.set_title("radio buttons")
        self.window.set_border_width(0)

        box1 = gtk.VBox(gtk.FALSE, 0)
        self.window.add(box1)
        box1.show()

        box2 = gtk.VBox(gtk.FALSE, 10)
        box2.set_border_width(10)
        box1.pack_start(box2, gtk.TRUE, gtk.TRUE, 0)
        box2.show()

        button = gtk.RadioButton(None, "radio button1")
        button.connect("toggled", self.callback, "radio button 1")
        box2.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
        button.show()

        button = gtk.RadioButton(button, "radio button2")
        button.connect("toggled", self.callback, "radio button 2")
        button.set_active(gtk.TRUE)
        box2.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
        button.show()

        button = gtk.RadioButton(button, "radio button3")
        button.connect("toggled", self.callback, "radio button 3")
        box2.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
        button.show()

        separator = gtk.HSeparator()
        box1.pack_start(separator, gtk.FALSE, gtk.TRUE, 0)
        separator.show()

        box2 = gtk.VBox(gtk.FALSE, 10)
        box2.set_border_width(10)
        box1.pack_start(box2, gtk.FALSE, gtk.TRUE, 0)
        box2.show()

        button = gtk.Button("close")
        button.connect_object("clicked", self.close_application, self.window,
                              None)
        box2.pack_start(button, gtk.TRUE, gtk.TRUE, 0)
        button.set_flags(gtk.CAN_DEFAULT)
        button.grab_default()
        button.show()
        self.window.show()

def main():
    gtk.main()
    return 0        

if __name__ == "__main__":
    RadioButtons()
    main()