/usr/share/doc/python-gtk2-tutorial/html/ch-ButtonWidget.html is in python-gtk2-tutorial 2.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 6. The Button Widget</title><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="up" href="index.html" title="PyGTK 2.0 Tutorial"><link rel="previous" href="sec-WidgetsWithoutWindows.html" title="5.2. Widgets Without Windows"><link rel="next" href="sec-ToggleButtons.html" title="6.2. Toggle Buttons"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 6. The Button Widget</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-WidgetsWithoutWindows.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="sec-ToggleButtons.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="ch-ButtonWidget"></a>Chapter 6. The Button Widget</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch-ButtonWidget.html#sec-NormalButtons">6.1. Normal Buttons</a></span></dt><dt><span class="sect1"><a href="sec-ToggleButtons.html">6.2. Toggle Buttons</a></span></dt><dt><span class="sect1"><a href="sec-CheckButtons.html">6.3. Check Buttons</a></span></dt><dt><span class="sect1"><a href="sec-RadioButtons.html">6.4. Radio Buttons</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-NormalButtons"></a>6.1. Normal Buttons</h2></div></div><div></div></div><p>We've almost seen all there is to see of the button widget. It's
pretty simple. You can use the <tt class="function">gtk.Button</tt>() function to
create a button with a label by passing a string parameter, or to create a
blank button by not specifying a label string. It's then up to you to pack a
label or pixmap into this new button. To do this, create a new box, and then
pack your objects into this box using the usual
<tt class="methodname">pack_start</tt>() method, and then use the
<tt class="methodname">add</tt>() method to pack the box into the
button.</p><p>The function to create a button is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
button = <tt class="classname">gtk.Button</tt>(<b class="parameter"><tt>label</tt></b>=None, <b class="parameter"><tt>stock</tt></b>=None)
</pre></td></tr></table><p>if label text is specified it is used as the text on the button.
If stock is specified it is used to select a stock icon and text label for
the button. The stock items are:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
STOCK_DIALOG_INFO
STOCK_DIALOG_WARNING
STOCK_DIALOG_ERROR
STOCK_DIALOG_QUESTION
STOCK_DND
STOCK_DND_MULTIPLE
STOCK_ADD
STOCK_APPLY
STOCK_BOLD
STOCK_CANCEL
STOCK_CDROM
STOCK_CLEAR
STOCK_CLOSE
STOCK_CONVERT
STOCK_COPY
STOCK_CUT
STOCK_DELETE
STOCK_EXECUTE
STOCK_FIND
STOCK_FIND_AND_REPLACE
STOCK_FLOPPY
STOCK_GOTO_BOTTOM
STOCK_GOTO_FIRST
STOCK_GOTO_LAST
STOCK_GOTO_TOP
STOCK_GO_BACK
STOCK_GO_DOWN
STOCK_GO_FORWARD
STOCK_GO_UP
STOCK_HELP
STOCK_HOME
STOCK_INDEX
STOCK_ITALIC
STOCK_JUMP_TO
STOCK_JUSTIFY_CENTER
STOCK_JUSTIFY_FILL
STOCK_JUSTIFY_LEFT
STOCK_JUSTIFY_RIGHT
STOCK_MISSING_IMAGE
STOCK_NEW
STOCK_NO
STOCK_OK
STOCK_OPEN
STOCK_PASTE
STOCK_PREFERENCES
STOCK_PRINT
STOCK_PRINT_PREVIEW
STOCK_PROPERTIES
STOCK_QUIT
STOCK_REDO
STOCK_REFRESH
STOCK_REMOVE
STOCK_REVERT_TO_SAVED
STOCK_SAVE
STOCK_SAVE_AS
STOCK_SELECT_COLOR
STOCK_SELECT_FONT
STOCK_SORT_ASCENDING
STOCK_SORT_DESCENDING
STOCK_SPELL_CHECK
STOCK_STOP
STOCK_STRIKETHROUGH
STOCK_UNDELETE
STOCK_UNDERLINE
STOCK_UNDO
STOCK_YES
STOCK_ZOOM_100
STOCK_ZOOM_FIT
STOCK_ZOOM_IN
STOCK_ZOOM_OUT
</pre></td></tr></table><p>The <a href="examples/buttons.py" target="_top"><span><b class="command">buttons.py</b></span></a> program
provides an example of using <tt class="function">gtk.Button</tt>() to create a
button with an image and a label in it. I've broken up the code to create a
box from the rest so you can use it in your programs. There are further
examples of using images later in the tutorial. <a href="ch-ButtonWidget.html#buttonfig" title="Figure 6.1. Button with Pixmap and Label">Figure 6.1, “Button with Pixmap and Label”</a>
shows the window containing a button with both a pixmap and a label:</p><div class="figure"><a name="buttonfig"></a><p class="title"><b>Figure 6.1. Button with Pixmap and Label</b></p><div class="mediaobject" align="center"><img src="figures/button.png" align="middle" alt="Button with Pixmap and Label"></div></div><p>The source code for the <a href="examples/buttons.py" target="_top"><span><b class="command">buttons.py</b></span></a> program
is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
1 #!/usr/bin/env python
2
3 # example-start buttons buttons.py
4
5 import pygtk
6 pygtk.require('2.0')
7 import gtk
8
9 # Create a new hbox with an image and a label packed into it
10 # and return the box.
11
12 def xpm_label_box(parent, xpm_filename, label_text):
13 # Create box for xpm and label
14 box1 = gtk.HBox(False, 0)
15 box1.set_border_width(2)
16
17 # Now on to the image stuff
18 image = gtk.Image()
19 image.set_from_file(xpm_filename)
20
21 # Create a label for the button
22 label = gtk.Label(label_text)
23
24 # Pack the pixmap and label into the box
25 box1.pack_start(image, False, False, 3)
26 box1.pack_start(label, False, False, 3)
27
28 image.show()
29 label.show()
30 return box1
31
32 class Buttons:
33 # Our usual callback method
34 def callback(self, widget, data=None):
35 print "Hello again - %s was pressed" % data
36
37 def __init__(self):
38 # Create a new window
39 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
40
41 self.window.set_title("Image'd Buttons!")
42
43 # It's a good idea to do this for all windows.
44 self.window.connect("destroy", lambda wid: gtk.main_quit())
45 self.window.connect("delete_event", lambda a1,a2:gtk.main_quit())
46
47 # Sets the border width of the window.
48 self.window.set_border_width(10)
49
50 # Create a new button
51 button = gtk.Button()
52
53 # Connect the "clicked" signal of the button to our callback
54 button.connect("clicked", self.callback, "cool button")
55
56 # This calls our box creating function
57 box1 = xpm_label_box(self.window, "info.xpm", "cool button")
58
59 # Pack and show all our widgets
60 button.add(box1)
61
62 box1.show()
63 button.show()
64
65 self.window.add(button)
66 self.window.show()
67
68 def main():
69 gtk.main()
70 return 0
71
72 if __name__ == "__main__":
73 Buttons()
74 main()
</pre></td></tr></table><p>Lines 12-34 define the <tt class="function">xpm_label_box</tt>()
helper function which creates a horizontal box with a border width of 2
(lines 14-15), populates it with an image (lines 22-23) and a label (line
26).</p><p>Lines 36-70 define the <tt class="classname">Buttons</tt> class.
Lines 41-70 define the instance initialization method which creates a window
(line 43), sets the title (line 45), connects the "delete_event" and
"destroy" signals (lines 48-49). Line 55 creates the button without a label.
Its "clicked" signal gets connected to the
<tt class="methodname">callback</tt>() method in line 58. The
<tt class="function">xpm_label_box</tt>() function is called in line 61 to create
the image and label to put in the button in line 64.</p><p>The <tt class="function">xpm_label_box</tt>() function could be used
to pack xpm's and labels into any widget that can be a container.</p><p>The Button widget has the following signals:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
pressed - emitted when pointer button is pressed within Button widget
released - emitted when pointer button is released within Button widget
clicked - emitted when pointer button is pressed and then released within Button widget
enter - emitted when pointer enters Button widget
leave - emitted when pointer leaves Button widget
</pre></td></tr></table></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-WidgetsWithoutWindows.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sec-ToggleButtons.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.2. Widgets Without Windows </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6.2. Toggle Buttons</td></tr></table></div></body></html>
|