Reputation: 543
I am using a GTK drawing area to display circles. I am creating the circles by drawing 2 pi arcs and filling them with a color. I want to give the color of the circles an alpha. This way when a circle is drawn on top of another circle I will be able to see the circle underneath.
Does anyone have an ideas to achieve what I want?
Maybe I missed something that would be useful in the gtk.gdk.GC.
Thanks, Ian
Upvotes: 0
Views: 571
Reputation: 773
Try Cairo, please. Here is a deom:
#!/usr/bin/env python3
import cairo
from gi.repository import Gtk
import math
class Demo(Gtk.Window):
def __init__(self):
super(Demo, self).__init__()
self.init_ui()
def init_ui(self):
darea = Gtk.DrawingArea()
darea.connect('draw', self.on_draw)
self.add(darea)
self.set_title('Fill & stroke')
self.resize(300, 150)
self.set_position(Gtk.WindowPosition.CENTER)
self.connect('delete-event', Gtk.main_quit)
self.show_all()
def on_draw(self, window, cr):
cr.set_source_rgba(0.3, 0.4, 0.5, 0.5)
cr.arc(60, 60, 40, 0, 2*math.pi)
cr.fill()
cr.set_source_rgba(0.5, 0.2, 0.7, 0.5)
cr.arc(70, 60, 30, 0, 2*math.pi)
cr.fill()
def main():
app = Demo()
Gtk.main()
if __name__ == '__main__':
main()
And here is the screenshot:
Visit here to learn more about Cairo.
Upvotes: 1