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:
Nathan Hyde 2015-07-01 16:19:08 -07:00
parent 616be48357
commit c61cc96a87
1 changed files with 6 additions and 7 deletions

View File

@ -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()