From c61cc96a87ad683f338199423dacf29a858e424a Mon Sep 17 00:00:00 2001 From: Nathan Hyde Date: Wed, 1 Jul 2015 16:19:08 -0700 Subject: [PATCH] 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 --- examples/guide/firstwidget/6_button.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/guide/firstwidget/6_button.py b/examples/guide/firstwidget/6_button.py index 667aed5e7..428a6bb00 100644 --- a/examples/guide/firstwidget/6_button.py +++ b/examples/guide/firstwidget/6_button.py @@ -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()