/usr/share/doc/python-gtk2-tutorial/html/ch-MiscellaneousWidgets.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 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 9. Miscellaneous Widgets</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-RangeWidgetEample.html" title="8.5. Range Widget Example"><link rel="next" href="sec-Arrows.html" title="9.2. Arrows"></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 9. Miscellaneous Widgets</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-RangeWidgetEample.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="sec-Arrows.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="ch-MiscellaneousWidgets"></a>Chapter 9. Miscellaneous Widgets</h2></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="ch-MiscellaneousWidgets.html#sec-Labels">9.1. Labels</a></span></dt><dt><span class="sect1"><a href="sec-Arrows.html">9.2. Arrows</a></span></dt><dt><span class="sect1"><a href="sec-TooltipsObject.html">9.3. The Tooltips Object</a></span></dt><dt><span class="sect1"><a href="sec-ProgressBars.html">9.4. Progress Bars</a></span></dt><dt><span class="sect1"><a href="sec-Dialogs.html">9.5. Dialogs</a></span></dt><dt><span class="sect1"><a href="sec-Images.html">9.6. Images</a></span></dt><dd><dl><dt><span class="sect2"><a href="sec-Images.html#id3109973">9.6.1. Pixmaps</a></span></dt></dl></dd><dt><span class="sect1"><a href="sec-Rulers.html">9.7. Rulers</a></span></dt><dt><span class="sect1"><a href="sec-Statusbars.html">9.8. Statusbars</a></span></dt><dt><span class="sect1"><a href="sec-TextEntries.html">9.9. Text Entries</a></span></dt><dt><span class="sect1"><a href="sec-SpinButtons.html">9.10. Spin Buttons</a></span></dt><dt><span class="sect1"><a href="sec-ComboWidget.html">9.11. Combo Widget</a></span></dt><dt><span class="sect1"><a href="sec-Calendar.html">9.12. Calendar</a></span></dt><dt><span class="sect1"><a href="sec-ColorSelection.html">9.13. Color Selection</a></span></dt><dt><span class="sect1"><a href="sec-FileSelections.html">9.14. File Selections</a></span></dt><dt><span class="sect1"><a href="sec-FontSelectionDialog.html">9.15. Font Selection Dialog</a></span></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-Labels"></a>9.1. Labels</h2></div></div><div></div></div><p><tt class="classname">Labels</tt> are used a lot in GTK, and are
relatively simple. <tt class="classname">Labels</tt> emit no signals as they do
not have an associated X window. If you need to catch signals, or do
clipping, place it inside a <tt class="classname">EventBox</tt> (see <a href="ch-ContainerWidgets.html#sec-EventBox" title="10.1. The EventBox">Section 10.1, “The EventBox”</a>) widget or a <tt class="classname">Button</tt>
(see <a href="ch-ButtonWidget.html#sec-NormalButtons" title="6.1. Normal Buttons">Section 6.1, “Normal Buttons”</a>) widget.</p><p>To create a new label, use:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
label = gtk.Label(<b class="parameter"><tt>str</tt></b>)
</pre></td></tr></table><p>The sole argument is the string you wish the label to
display. To change the label's text after creation, use the
method:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
label.set_text(<b class="parameter"><tt>str</tt></b>)
</pre></td></tr></table><p><i class="parameter"><tt>label</tt></i> is the label you created
previously, and <i class="parameter"><tt>str</tt></i> is the new string. The space
needed for the new string will be automatically adjusted if needed. You can
produce multi-line labels by putting line breaks in the label string.</p><p>To retrieve the current string, use:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
str = label.get_text()
</pre></td></tr></table><p><i class="parameter"><tt>label</tt></i> is the label you've created, and
<i class="parameter"><tt>str</tt></i> is the return string. The
<i class="parameter"><tt>label</tt></i> text can be justified using:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
label.set_justify(<b class="parameter"><tt>jtype</tt></b>)
</pre></td></tr></table><p>Values for <i class="parameter"><tt>jtype</tt></i> are:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
JUSTIFY_LEFT # the default
JUSTIFY_RIGHT
JUSTIFY_CENTER
JUSTIFY_FILL # does not work
</pre></td></tr></table><p>The label widget is also capable of line wrapping the text
automatically. This can be activated using:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
label.set_line_wrap(<b class="parameter"><tt>wrap</tt></b>)
</pre></td></tr></table><p>The <i class="parameter"><tt>wrap</tt></i> argument takes a
<tt class="literal">TRUE</tt> or <tt class="literal">FALSE</tt> value.</p><p>If you want your label underlined, then you can set a pattern on
the label:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
label.set_pattern(<b class="parameter"><tt>pattern</tt></b>)
</pre></td></tr></table><p>The <i class="parameter"><tt>pattern</tt></i> argument indicates how the
underlining should look. It consists of a string of underscore and space
characters. An underscore indicates that the corresponding character in the
label should be underlined. For example, the string <tt class="literal">"__
__"</tt> would underline the first two characters and fourth and fifth
characters. If you simply want to have an underlined accelerator
("mnemonic") in your label, you should use
<tt class="methodname">set_text_with_mnemonic</tt>(<b class="parameter"><tt>str</tt></b>), not
<tt class="methodname">set_pattern</tt>().</p><p>The <a href="examples/label.py" target="_top"><span><b class="command">label.py</b></span></a> program is a
short example to illustrate these methods. This example makes use of the
<tt class="classname">Frame</tt> (see <a href="sec-Frames.html" title="10.5. Frames">Section 10.5, “Frames”</a>) widget
to better demonstrate the label styles. You can ignore this for now as the
<tt class="classname">Frame</tt> widget is explained later on.</p><p>In GTK+ 2.0, label text can contain markup for font and other
text attribute changes, and labels may be selectable (for copy-and-paste).
These advanced features won't be explained here.</p><p><a href="ch-MiscellaneousWidgets.html#labelexamplesfig" title="Figure 9.1. Label Examples">Figure 9.1, “Label Examples”</a> illustrates the result of running the
example program:</p><div class="figure"><a name="labelexamplesfig"></a><p class="title"><b>Figure 9.1. Label Examples</b></p><div class="mediaobject" align="center"><img src="figures/labels.png" align="middle" alt="Label Examples"></div></div><p>The <a href="examples/label.py" target="_top"><span><b class="command">label.py</b></span></a> source code
is:</p><table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="programlisting">
1 #!/usr/bin/env python
2
3 # example label.py
4
5 import pygtk
6 pygtk.require('2.0')
7 import gtk
8
9 class Labels:
10 def __init__(self):
11 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
12 self.window.connect("destroy", lambda w: gtk.main_quit())
13
14 self.window.set_title("Label")
15 vbox = gtk.VBox(False, 5)
16 hbox = gtk.HBox(False, 5)
17 self.window.add(hbox)
18 hbox.pack_start(vbox, False, False, 0)
19 self.window.set_border_width(5)
20
21 frame = gtk.Frame("Normal Label")
22 label = gtk.Label("This is a Normal label")
23 frame.add(label)
24 vbox.pack_start(frame, False, False, 0)
25
26 frame = gtk.Frame("Multi-line Label")
27 label = gtk.Label("This is a Multi-line label.\nSecond line\n"
28 "Third line")
29 frame.add(label)
30 vbox.pack_start(frame, False, False, 0)
31
32 frame = gtk.Frame("Left Justified Label")
33 label = gtk.Label("This is a Left-Justified\n"
34 "Multi-line label.\nThird line")
35 label.set_justify(gtk.JUSTIFY_LEFT)
36 frame.add(label)
37 vbox.pack_start(frame, False, False, 0)
38
39 frame = gtk.Frame("Right Justified Label")
40 label = gtk.Label("This is a Right-Justified\nMulti-line label.\n"
41 "Fourth line, (j/k)")
42 label.set_justify(gtk.JUSTIFY_RIGHT)
43 frame.add(label)
44 vbox.pack_start(frame, False, False, 0)
45
46 vbox = gtk.VBox(False, 5)
47 hbox.pack_start(vbox, False, False, 0)
48 frame = gtk.Frame("Line wrapped label")
49 label = gtk.Label("This is an example of a line-wrapped label. It "
50 "should not be taking up the entire "
51 "width allocated to it, but automatically "
52 "wraps the words to fit. "
53 "The time has come, for all good men, to come to "
54 "the aid of their party. "
55 "The sixth sheik's six sheep's sick.\n"
56 " It supports multiple paragraphs correctly, "
57 "and correctly adds "
58 "many extra spaces. ")
59 label.set_line_wrap(True)
60 frame.add(label)
61 vbox.pack_start(frame, False, False, 0)
62
63 frame = gtk.Frame("Filled, wrapped label")
64 label = gtk.Label("This is an example of a line-wrapped, filled label. "
65 "It should be taking "
66 "up the entire width allocated to it. "
67 "Here is a sentence to prove "
68 "my point. Here is another sentence. "
69 "Here comes the sun, do de do de do.\n"
70 " This is a new paragraph.\n"
71 " This is another newer, longer, better "
72 "paragraph. It is coming to an end, "
73 "unfortunately.")
74 label.set_justify(gtk.JUSTIFY_FILL)
75 label.set_line_wrap(True)
76 frame.add(label)
77 vbox.pack_start(frame, False, False, 0)
78
79 frame = gtk.Frame("Underlined label")
80 label = gtk.Label("This label is underlined!\n"
81 "This one is underlined in quite a funky fashion")
82 label.set_justify(gtk.JUSTIFY_LEFT)
83 label.set_pattern(
84 "_________________________ _ _________ _ ______ __ _______ ___")
85 frame.add(label)
86 vbox.pack_start(frame, False, False, 0)
87 self.window.show_all ()
88
89 def main():
90 gtk.main()
91 return 0
92
93 if __name__ == "__main__":
94 Labels()
95 main()
</pre></td></tr></table><p>Note that the "Filled, wrapped label" is not fill
justified.</p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-RangeWidgetEample.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-Arrows.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">8.5. Range Widget Example </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.2. Arrows</td></tr></table></div></body></html>
|