# Properties (Python)

An explanation of properties, getters and setters.
Sebastian Pölsterl
sebp@k-d-w.org 2011
Marta Maria Casetti
mmcasetti@gmail.com 2012

# Properties

# Overview

Properties describe the configuration and state of widgets, and each widget has its own particular set of properties. For example, a widget such as a button or a label has the property "label" which contains the text of the widget. You can specify the name and value of any number of properties as keyword arguments when creating an instance of a widget: for example, to create a label aligned to the right with the text “Hello World” and an angle of 25 degrees, you can use:

label = Gtk.Label(label="Hello World", angle=25, halign=Gtk.Align.END)

This is equivalent to:

label = Gtk.Label() label.set_label("Hello World") label.set_angle(25) label.set_halign(Gtk.Align.END)

Once you have created such a label, you can get the text with the getter `label.get_label()`.

Instead of using getters and setters you can also get and set the properties with `get_property("prop-name")` and `set_property("prop-name", value)`, respectively.

# References

Basics - Properties in Python Gtk+ 3 Tutorial