У меня есть собственный класс, подобный этому,
in.kv,
<ProductButton>:
BoxLayout:
orientation: "horizontal"
padding: 10, 10, 10, 10
Image:
id: image1
source:
BoxLayout:
orientation: "vertical"
padding: 20, 20, 20, 20
Label:
id: label1
text:
Label:
id: label2
text:
В .py я собираюсь добавить ProductButton на экран.
class ProductButton(ButtonBehavior, BoxLayout):
pass
class ProductPage(Screen):
def on_pre_enter(self, *args):
global real_result
for x in range(len(real_result)):
self.ids.box.add_widget(ProductButton())
Я хочу изменить изображение и текст надписей в соответствии с различными x, и мне не удалось. Я попытался self.ids.box.add_widget(ProductButton(self.ids.image1.source="123.png"))
, и я получил ошибку keyword can't be an expression
Я также попытался
product_button = ProductButton()
image1 = product_button.ids.image1.source
for x in range(len(real_result)):
self.ids.box.add_widget(ProductButton(image1="123.png"))
, и я получил TypeError: object.__init__() takes exactly one argument (the instance to initialize)
Я хочу изменить изображение и тексты, ссылаясь на идентификаторы в .py файле. Как?