Динамически изменить текстуру Ellipse в kivy, python - PullRequest
0 голосов
/ 04 июля 2019

Я хочу добавить текстуру в Ellipse из кода Python.

.kv файл:

    <User>:
        user_name: username
        user_pic: userpic
        size_hint_y: None
        height: '40dp'
        orientation: 'horizontal'
        padding: 2
        BoxLayout:
            id: userpic
            size_hint_x: 0.2
            canvas.before:
                Ellipse:
                    group: 'pic'
                    pos: self.pos
                    size: self.size

python code:
    class User(BoxLayout):
        user_name = ObjectProperty(None)
        def init(self, texture, name):
            self.ids.user_pic.canvas.get_group['pic'][0].texture = texture
            self.user_name.text = name

some portion of the other code:
user = User()
    img = np.array(json.loads(user_dtls[i][1])).reshape(56, 56, 3)
                img = img.astype(np.uint8)
                img = cv2.flip(img, 0)
                texture = Texture.create(size=(56, 56))
                texture.blit_buffer(img.tostring(), colorfmt='bgr', bufferfmt='ubyte')
                user.init(texture, 'demo')
                self.uh.add_widget(user)

получаю следующую ошибку:

self.ids.user_pic.canvas.get_group['pic'][0].texture = texture

Файл "kivy \ properties.pyx", строка 841, в kivy.properties.ObservableDict. GetAttr AttributeError: у объекта 'super' нет атрибута ' getattr '

1 Ответ

0 голосов
/ 04 июля 2019

Итак, несмотря на отсутствие минимального воспроизводимого примера, вот что я думаю о ваших главных проблемах:

  • с использованием userpic в одном месте и user_pic в другом
  • get_group - это метод, а не список, поэтому он должен выглядеть как get_group('pic')
  • ваша группа pic создается внутри группы before (вы используете canvas.before), поэтому canvas.get_group должно быть canvas.before.get_group
...