D
D
Dima Gordey2020-05-08 14:23:37
Python
Dima Gordey, 2020-05-08 14:23:37

Why does the "name 'NumericProperty' is not defined" error occur?

The code:

from kivy.app import App
from kivy.uix.widget import Widget

class PongBall(Widget):
  velocity_x = NumericProperty(0)
  velocity_y = NumericProperty(0)

  velocity = ReferenceListProperty(velocity_x, velocity_y)

  def move(self):
    self.pos = Vector(*self.velocity) + self.pos

class PongGame(Widget):
  pass

class PongApp(App):
  def build(self):
    return PongGame()

if __name__=='__main__':
  PongApp().run()


kv file:
#:kivy 1.11.1

<PongBall>:
    size:50,50
    canvas:
        Ellipse:
            pos:self.pos
            size:self.size
<PongGame>:     
    canvas: 
        Rectangle: 
            pos:self.center_x-5,0 
            size:10,self.height 
            
    Label: 
        font_size:70   
        center_x:root.width / 4 
        top:root.top-50 
        text:"0" 
        
    Label: 
        font_size: 70   
        center_x: root.width * 3 / 4 
        top:root.top - 50 
        text:"0"


The error itself:
Traceback (most recent call last):
   File "main.py", line 4, in <module>
     class PongBall(Widget):
   File "main.py", line 5, in PongBall
     velocity_x = NumericProperty(0)
 NameError: name 'NumericProperty' is not defined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-05-08
@Dimagordey551

You lost your import.
from kivy.properties import NumericProperty

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question