blob: 0ef1d2b8526682c5e7466d007826324ec09b459d (
plain)
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
|
#!/usr/bin/env python
""" Simple example of creating a basic window and button.
Also adds a tooltip. """
import gtk
def hello_cb(widget, main_window):
""" Callback function that prints a message and destroys the window """
print "Hello World"
main_window.destroy()
def destroy_cb(widget, main_window):
""" Callback function to hide the main window and then terminate. """
main_window.hide()
gtk.main_quit()
def main():
""" Sets up the application
Forms the widgets and connects callback functions to the signals """
window = gtk.Window( type=gtk.WINDOW_TOPLEVEL )
window.set_title("Hello World")
window.set_default_size(200, 200)
window.set_border_width(10)
window.connect("destroy", destroy_cb, window)
button = gtk.Button(label="Hello World")
window.add(button)
button.connect("clicked", hello_cb, window)
# setup tooltips and associate them with the button
tt = gtk.Tooltips()
tt.set_tip(button, 'Prints "Hello World"', None)
tt.enable()
# shows the window and any child objects (button in this example)
window.show_all()
gtk.main()
# if we're being run normally then call the main function
if __name__ == '__main__':
main()
|