This is similar but just using GTK. You get the iters for the start and end of the range that you want to tag and apply the tag to it.
Eric import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk class TextBox(Gtk.TextView): def __init__(self): Gtk.TextView.__init__(self) textbuffer = self.get_buffer() textbuffer.set_text("Some text to tag.\nAnother line to tag.") start = textbuffer.get_start_iter() end = textbuffer.get_end_iter() tag = textbuffer.create_tag("blue_tag", background="blue", foreground="yellow") textbuffer.apply_tag(tag, start, end) class MainWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Text Tag") self.set_default_size(300, 100) self.tb = TextBox() self.tb.set_hexpand(True) self.tb.set_vexpand(True) self.grid = Gtk.Grid() self.grid.attach(self.tb, 0, 0, 1, 1) self.add(self.grid) win = MainWindow() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list