How to resolve Python Kivy object is not subscriptable.

Asked 2 years ago, Updated 2 years ago, 56 views

When I press the Change Text button, I want to run label_change for one class, but I get the error TypeError: 'kivy.properties.DictProperty' object is not subscriptable with the code below.
What's wrong?I'm a beginner in programming, so I couldn't understand the error at all...I'm sorry, but could someone please tell me the correct way to describe it?
If you rewrite the .kv file and run "Base Class label_change", it works well.

.py

 from kivy.app import App
from kivy.uix.boxlayout import BoxLayout

Class Base (BoxLayout):
    def__init__(self,**kwargs):
        super().__init__(**kwargs)

    deflabel_change(self):
        self.ids ["info"].text="A"

class One (object):
    def__init__(self, age="15", sex="Female"):
        self.age=age
        self.sex=sex

    deflabel_change(self):
        MainFrame.ids ["info"].text="A"

~~Omitted~~

.kv

#:import One__main__.One

<Base>:
    orientation:"vertical"
    Label:
        id —info
        text:"label"
    BoxLayout:
        Button:
            text:"Change Text"
            on_press —One().label_change()

python python3 kivy

2022-09-30 21:29

1 Answers

I'm not sure because the code has been omitted. Perhaps the MainFrame class inherits the App class and actually runs it?
If possible, I would be able to advise you if you could include all the codes.

However, with this content, I think the content of the error is that there is no array of MainFrame.ids ["info"].text.
This is the contents of the id in the KV file, so I think you should look back at the id of the Pong Game in the tutorial

Japanese translation: https://pyky.github.io/kivy-doc-ja/tutorials/pong.html#adding-ball-animation


2022-09-30 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.