我是kivy的新手,我试图将小部件攻击到浮动布局,我使用了一个示例中的代码:
http://kivy.org/docs/guide/firstwidget.html
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Color, Ellipse, Line
from kivy.uix.floatlayout import FloatLayout
class MyPaintWidget(Widget):
def on_touch_down(self, touch):
color = (random(), random(), random())
with self.canvas:
Color(*color)
d = 15.
Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
touch.ud['line'] = Line(points=(touch.x, touch.y))
def on_touch_move(self, touch):
touch.ud['line'].points += [touch.x, touch.y]
class KivyDotsLayout(FloatLayout):
def __init__(self):
super(KivyDotsLayout, self).__init__()
self.add_widget(MyPaintWidget)
class MyPaintApp(App):
def build(self):
return KivyDotsLayout()
if __name__ == '__main__':
MyPaintApp().run()<code>
然后他给了我这个错误:
Traceback (most recent call last):
File "/Users/Painkiller/PycharmProjects/Prova/Game/DotsGAme/example.py", line 40, in <module>
MyPaintApp().run()
File "/Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/kivy/app.py", line 798, in run
root = self.build()
File "/Users/Painkiller/PycharmProjects/Prova/Game/DotsGAme/example.py", line 36, in build
return KivyDotsLayout()
File "/Users/Painkiller/PycharmProjects/Prova/Game/DotsGAme/example.py", line 29, in __init__
self.add_widget(MyPaintWidget)
File "/Applications/Kivy.app/Contents/Resources/venv/lib/python2.7/site-packages/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
但是没有绑定...请帮帮我
答案 0 :(得分:2)
self.add_widget(MyPaintWidget)
这应该是self.add_widget(MyPaintWidget())
- 您需要类的实例,而不是类声明本身。