source: pkg/pygtk/branches/upstream/current/examples/simple/tooltip.py @ 4

Revision 4, 1.2 KB checked in by alanbach-guest, 6 years ago (diff)

[svn-inject] Installing original source of pygtk

Line 
1#!/usr/bin/env python
2
3""" Simple example of creating a basic window and button.
4    Also adds a tooltip. """
5
6import gtk
7
8def hello_cb(widget, main_window):
9    """ Callback function that prints a message and destroys the window """
10    print "Hello World"
11    main_window.destroy()
12
13def destroy_cb(widget, main_window):
14    """ Callback function to hide the main window and then terminate. """
15    main_window.hide()
16    gtk.main_quit()
17
18def main():
19    """ Sets up the application
20        Forms the widgets and connects callback functions to the signals """
21
22    window = gtk.Window( type=gtk.WINDOW_TOPLEVEL )
23    window.set_title("Hello World")
24    window.set_default_size(200, 200)
25    window.set_border_width(10)
26    window.connect("destroy", destroy_cb, window)
27
28    button = gtk.Button(label="Hello World")
29    window.add(button)
30    button.connect("clicked", hello_cb, window)
31
32    # setup tooltips and associate them with the button
33    tt = gtk.Tooltips()
34    tt.set_tip(button, 'Prints "Hello World"', None)
35    tt.enable()
36
37    # shows the window and any child objects (button in this example)
38    window.show_all()
39    gtk.main()
40
41# if we're being run normally then call the main function
42if __name__ == '__main__':
43    main()
Note: See TracBrowser for help on using the repository browser.