简体   繁体   中英

No name 'ObjectProperty' in module 'kivy.properties' - Python Kivy

When I try to import ObjectProperties from kivy.properties, I get an error: "No name 'ObjectProperty' in module 'kivy.properties'pylint(no-name-in-module)"

from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout                                               
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.label import Label
from kivy.config import Config
from kivy.event import EventDispatcher
from kivy.properties import ObjectProperty

Config.set('graphics', 'width', 1000)
Config.set('graphics', 'height', 1000)
Config.set('graphics', 'resizable', False)

class GridContainer(GridLayout):
text_input1 = ObjectProperty()
    label1 = ObjectProperty()

    def count_sum(self):
        self.label1.text = int(self.text_input1.text[0]) + int(self.text_input1.text[1])

class MyApp(App):
    def build(self):
        GridContainer()
        return GridContainer()

Are there any ways to solve this problem?

I found myself in the same situation simply because I thought python only accepts libraries written in python. Python codes/libraries can be made to run faster by compiling them into a mixture of C and Python codes as observed with the properties library located in the kivy directory of site-packages of your python installation folder . Using this method, the compiled python codes can be imported without any troubles just as prior to compilation.

Myself, I have not seen any extension that lints cython codes and they are all built to work with libraries developed with python not cython. Thus, they tend to have problems linting those that have been written/compiled to cython.

As inclement clearly stated, this is not an issue you should worry about if the program runs fine. It is a problem with IDE linting extensions, they cant lint cython codes. You can go with Jayden solution if you dont want to be seeing the squiggy red lines all the time.

I hope this clearifies things..?

I found a workaround:

  1. replace from kivy.properties import ObjectProperty with import kivy.properties as kyprops
  2. type kyprops anytime you need to declare ObjectProperty

Let me know if that helps!

If the code runs fine, this is just a bug in your linter. As already linked by others, it is probably not capable of properly understanding imports from cython-built libraries.

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