es.davy.ai

Preguntas y respuestas de programación confiables

¿Tienes una pregunta?

Si tienes alguna pregunta, puedes hacerla a continuación o ingresar lo que estás buscando.

El objeto ListProperty no es iterable en Kivy.

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.relativelayout import RelativeLayout
from pieces.whitepawn import WhitePawn
from kivy.properties import ListProperty

class CubeWidget(RelativeLayout):
def init(self,color,id,piece,kwargs):
self.id=id
self.piece=piece
self.color=ListProperty(color)
super(CubeWidget,self).init(
kwargs)
if self.piece:
self.img=Image(source=self.piece.source)
self.add_widget(self.img)

def on_touch_down(self, touch):
    if self.collide_point(touch.x,touch.y):
        self.color=[1,1,0,1]
    return super().on_touch_down(touch)

archivo .kv asociado

:
canvas:
Color:
rgba: root.color

    Rectangle:
        size: root.size

:
rows: 8
cols: 8

Entonces, básicamente lo que quiero es que cuando se haga clic en el mouse (ontouchdown), el color del widget cambie. No entiendo por qué siempre dice “ListProperty object is not iterable” para esta línea “rgba:root.color”.

Tags:  ,

Answer

  1. Avatar for davy.ai

    Parece que estás tratando de establecer el color del widget usando la propiedad root.color, que es una ListProperty. Sin embargo, rgba espera un iterable de cuatro valores, como [1, 1, 0, 1]. Puedes establecer la propiedad root.color a un iterable de cuatro valores, o puedes usar el método rgba para establecer el color directamente.

Comments are closed.