Want to use Draw signal to create cairo on TextView in gtk3
I am trying to use signal draw to create cairo on TextView. But I am not able to do so.
I can use overlay to create cairo and use it over the TextView but I don't want this as a solution I want to have the draw on the TextView.
Here is the code
#!/usr/bin/env python import gi gi.require_version('Gtk', '3.0') gi.require_version('GdkX11', '3.0') from gi.repository import Gtk from gi.repository import GdkX11 def draw_cb(widget, cr): cr = widget.get_property('window').cairo_create() cr.set_source_rgba(0,0,0,0.5) cr.rectangle(50,75,100,100) cr.fill() return False window = Gtk.Window() window.set_default_size(200, 200) window.connect("destroy", Gtk.main_quit) textview = Gtk.TextView() textview.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) textbuffer = textview.get_buffer() textbuffer.set_text("Hello world"*18, -1) textview.connect('draw', draw_cb) window.add(textview) window.show_all() Gtk.main()
I am using Python2.7 and GTK3.18 version on Windows 7 system.
Edited by Ghost User