I am trying to draw an array of circles in a Gtk Window. I can draw one in a Gtk.DrawingArea and when the DrawingArea is the only object, it expands to fit the window. However, when I put multiple in a Gtk.Grid, they fail to expand to fill the Grid.
How do I get them to fill the grid?
I reviewed this post which referred to this page, but they did not solve the problem (or I failed to grasp the concept).
I have tried to set the properties expand, hexpand, vexpand, hexpand_set, and vexpand_set to True, and set_halign, and set_valign to Gtk.Align.FILL to no avail
My circles are created via CircleArea.py
from gi.repository import Gtk
import cairo
import math
class CircleArea(Gtk.DrawingArea):
"""Establishes the space for the circle and paints the circle in it"""
def __init__(self):
super(CircleArea, self).__init__()
self.hexpand = True
self.vexpand = True
self.set_halign = Gtk.Align.FILL
self.set_valign = Gtk.Align.FILL
self.connect('draw', self.on_draw)
def on_draw(self, widget, cr):
height = widget.get_allocated_height()
width = widget.get_allocated_width()
smaller = width if width < height else height
cr.set_source_rgb(self.red, self.green, self.blue)
cr.arc(height / 2, width / 2, smaller * 0.45, 0, 2 * math.pi)
cr.fill()
And the window itself is in Grid.py
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from CircleArea import CircleArea
class CircleWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Circle Grid")
self.set_border_width(10)
self.grid = Gtk.Grid()
self.circle_area1 = CircleArea()
self.circle_area2 = CircleArea()
self.grid.attach(self.circle_area1, 0, 0, 1, 1)
self.grid.attach(self.circle_area2, 1, 0, 1, 1)
self.add(self.grid)
win = CircleWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
I expect the circles to fill the available grid space, but instead they are both of size 1x1.