Re: Need help in GTK3 Draw event
- From: cecashon aol com
- To: dhruba doley gmail com, gtk-app-devel-list gnome org
- Subject: Re: Need help in GTK3 Draw event
- Date: Sat, 28 Apr 2018 13:34:27 -0400
Hi Dhrubajyoti,
The textview widget has text tags built in that you can use to draw rectangles around text. If you want to
draw a rectangle to block out text you can match the background and foreground colors. This code works on
Ubuntu16.04, GTK3.18 and Python2.7. Give it a try and see if something similar will work for what you are
working on.
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()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]