简体   繁体   中英

Kivy Python: confused with class and instance methods

I was trying kivy and while I was accessing class variables, I was forced to use 'self' for class variables or else it was producing error.

.kv 文件代码

This is the kivy code I was using. Below is the main.py code where I have confusion:

混乱所在的代码

This code works. Here I am using class variables and accessing them from 'self'.

According to me the code that should work is: 应该工作的代码

OR

应该工作的代码

But both of these codes give error. What is it that I am doing wrong?

Kivy properties are Python descriptors , an object supporting a special api that let's them provide instance-level behaviour when accessed from a class instance.

I think you also have a misconception about class vs instance level variables: variables defined at class level are also accessible via instances of the class, it's normal that you can access self.something_defined_at_class_level .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM