FleXX
FleXX

Reputation: 129

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?

Upvotes: 4

Views: 5730

Answers (3)

Prosper Ablordeppey
Prosper Ablordeppey

Reputation: 81

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..?

Upvotes: 3

Jaden Lee
Jaden Lee

Reputation: 11

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!

Upvotes: 1

inclement
inclement

Reputation: 29488

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.

Upvotes: 0

Related Questions