mirror of https://github.com/kivy/kivy.git
First Widget tutorial - use class variables
* Correct whitespace issues in 6_button.py * Make "painter" a class variable (self.painter) * Reference `self.clear_canvas` when binding the clear button callback * Call `self.painter.canvas.clear()` in button callback * Adjust the number of parameters for callback method
This commit is contained in:
parent
616be48357
commit
c61cc96a87
|
@ -23,17 +23,16 @@ class MyPaintApp(App):
|
|||
|
||||
def build(self):
|
||||
parent = Widget()
|
||||
painter = MyPaintWidget()
|
||||
self.painter = MyPaintWidget()
|
||||
clearbtn = Button(text='Clear')
|
||||
parent.add_widget(painter)
|
||||
clearbtn.bind(on_release=self.clear_canvas)
|
||||
parent.add_widget(self.painter)
|
||||
parent.add_widget(clearbtn)
|
||||
|
||||
def clear_canvas(obj):
|
||||
painter.canvas.clear()
|
||||
clearbtn.bind(on_release=clear_canvas)
|
||||
|
||||
return parent
|
||||
|
||||
def clear_canvas(self, obj):
|
||||
self.painter.canvas.clear()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
MyPaintApp().run()
|
||||
|
|
Loading…
Reference in New Issue