To specify that some text in the buffer should have specific formatting, you must define a tag to hold that formatting information, and then apply that tag to the region of text using create_tag("tag name", property)
and apply_tag(tag, start_iter, end_iter)
as in, for instance:
tag = textbuffer.create_tag("orange_bg", background="orange")
textbuffer.apply_tag(tag, start_iter, end_iter)
The following are some of the common styles applied to text:
- Background colour ("background" property)
- Foreground colour ("foreground" property)
- Underline ("underline" property)
- Bold ("weight" property)
- Italics ("style" property)
- Strikethrough ("strikethrough" property)
- Justification ("justification" property)
- Size ("size" and "size-points" properties)
- Text wrapping ("wrap-mode" property)
You can also delete particular tags later using remove_tag()
or delete all tags in a given region by calling remove_all_tags()
.