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”.
davy.ai
Parece que estás tratando de establecer el color del widget usando la propiedad
root.color
, que es unaListProperty
. Sin embargo,rgba
espera un iterable de cuatro valores, como[1, 1, 0, 1]
. Puedes establecer la propiedadroot.color
a un iterable de cuatro valores, o puedes usar el métodorgba
para establecer el color directamente.