# Displaying Text

TIP

Read Strings in GJS before starting this page!

# Gtk.Label

In GTK+ the simplest way to display text is using Gtk.Label. A Gtk.Label can contain simple, standard text or a variety of text styles using Markdown.

Learn Moreopen in new window

# Standard Text

To create a Gtk.Label with standard text simply pass the text as a JavaScript string to the label property of Gtk.Label in the constructor or using Gtk.Label.prototype.set_label().

Here is a simple example:

#!/usr/bin/env gjs

imports.gi.versions.Gtk = "3.0";
const { Gtk } = imports.gi;

Gtk.init(null);

let label = new Gtk.Label({ label: 'Hello!' });
let win = new Gtk.Window();
win.add(label);
win.show_all();

Gtk.main();
1
2
3
4
5
6
7
8
9
10
11
12
13

# Markup

To use markup you must pass useMarkup to the label.

Here is a simple example:

#!/usr/bin/env gjs

imports.gi.versions.Gtk = "3.0";
const { Gtk } = imports.gi;

Gtk.init(null);

let label = new Gtk.Label({
    useMarkup: true,
    label: '<b>Hello!</b>'
});
let win = new Gtk.Window();
win.add(label);
win.show_all();

Gtk.main();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Last Updated: 4/19/2021, 6:36:47 PM