kivy editable multicolumn list

Paulo da Silva p_s_d_a_s_i_l_v_a_ns at
Thu Sep 17 03:17:09 CEST 2015

Às 11:42 de 15-09-2015, Laura Creighton escreveu:
> In a message of Tue, 15 Sep 2015 03:31:49 +0100, Paulo da Silva writes:

>> Now I would like to change the background color the editable field.
> I just hardcoded it like this:
> integers_dict = {str(i): {'text': str(i), 'is_selected': False}
>                  for i in range(100)}
> which I pasted out of
> 'Using an Item View Template'.  This may have no relation to what you
> really want.
The example is closely based on an example that comes with kivy and is
supposed to run in the same directory. The fixtures there contain the
same as you hardcoded.

> you also need a line
> from import Color, Rectangle
It's there. I just forgot to mention it.

> Then you change your class definition to be:
> class EditableLabel(ListItemLabel):
>     def __init__(self,**kwargs):
>         super(EditableLabel, self).__init__(**kwargs)
>         self.bind(pos=self.redraw)
>         self.bind(size=self.redraw)
>     def redraw(self, *args):
>         self.canvas.clear()
>         with self.canvas:
>             Color(.5,.5,.5)
>             Rectangle(pos=self.pos,size=self.size)
This works but not as I expected. So it fixes the bug but the result I
got is not the pretended one.
I was trying to change the background color of the editable field.
That's the reason for the colored rectangle. But the rectangle overlaps
the text! So the entered text is hidden.

> I don't know why changing self.canvas.before: to self.canvas: in the redraw
> method was needed here.  I expected self.canvas.before to be what was
> needed, but doesn't seem that way.
> If you don't clear the canvas first, in the redraw the results look very
> silly to me.

In both situations redraw is entered with wrong self.pos and self.size
values. So there are extra rectangles drawn at wrong places and sizes.
I can't understand why.

Changing self.canvas.before to self.canvas and inserting
self.canvas.clear() fixes the problem.
But as I said the drawn rectangle hides the label text.

Thank you Laura.

More information about the Python-list mailing list