PyGTK - Label Class



A Label widget is useful to display non-editable text. Label is used by many other widgets internally. For example, Button has a label to show text on the face. Similarly, MenuItem objects have a label. A label is a windowless object, so it cannot receive events directly.

Label class has a simple constructor −

gtk.Label(str = None)

The following useful methods can be used with Label object −

S.NO Methods and Description
1

set_text()

This sets new text as label

2

get_text()

This returns text from label

3

set_use_underline()

If true, an underscore in the text indicates the next character should be used for the mnemonic accelerator key.

4

set_justify

This sets the alignment of the lines in the text of the label relative to each other.

Possible values are – gtk.JUSTIFY_LEFT, gtk.JUSTIFY_RIGHT, gtk.JUSTIFY_CENTER, and gtk.JUSTIFY_FILL.

5

Set_line_wrap()

If true, the line will be wrapped

6

set_selectable()

If true, the text in the label can be selected for copy-paste

7

set_width_chars()

This sets the width of a label

The following signals are emitted by label widget −

activate-current-link This gets emitted when the user activates a link in the label.
activate-link This gets emitted to activate a URI.
copy-clipboard This gets emitted when text is copied from the label to the clipboard.
Advertisements