4

I am trying to make a small tetris game for learning python with kivy. I am trying to create a custom widget with size 20,20. When I add it to the float layout and run the below code I receive the following error:

Error:

File "D:\OS Files\workspace\Tetris\holder.py", line 10, in __init__ self.add_widget(c)
File "C:\Kivy180\kivy\kivy\uix\floatlayout.py", line 115, in add_widget pos_hint=self._trigger_layout)
TypeError: descriptor 'bind' of 'kivy._event.EventDispatcher' object needs an argument

Code: holder.py File:

from items import Cell

class Holder(FloatLayout):
    def __init__(self, **kwargs):
        super(Holder,self).__init__(**kwargs)
        self.size=(300,300)
        c=Cell
        #c.pos= (20,20)
        self.add_widget(c)
        #self.add_widget(c)

items.py File:

from kivy.uix.widget import Widget
from kivy.graphics import *

class Cell(Widget):
    def __init__(self, **kwargs):
        super(Cell,self).__init__(**kwargs)
        with self.canvas:
            Color(1, 0, 0)
            Rectangle(pos=(0, 0), size=(50, 50))

        self.height=50
        self.width=50

main.py File:

from kivy.app import App
from holder import Holder

class start(App):
    def build(self):
        return Holder()

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

Could you please explain where I went wrong, I am stuck at the starting point itself. Regarding the error, I haven't written any events also, and it is just a widget class. Could you please explain where I went wrong in understanding kivy.

2
  • 1
    shouldn't c=Cell have parentheses and arguments and things...? Commented Jul 11, 2014 at 18:54
  • yup, thank you that helped. Can u keep it as a answer, I would mark it as correct. But for starter these are common error I believe, I am from VB.net and Visual Studios used to take care of small things Commented Jul 11, 2014 at 18:57

1 Answer 1

3
c=Cell

I bet you want c to be an instance of the Cell class. If you want to do that, you need to do:

c=Cell()
Sign up to request clarification or add additional context in comments.

3 Comments

I used "c.pos= (200,200)", however, the widget is getting added at corner only, could you please correct me, again.
Sorry, I don't actually know enough kivy to diagnose that problem :-(
Fine, you answered my actual question. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.