Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean canvas in kivy language

Tags:

python

kivy

You can call widget's canvas from kivy language using canvas[.before|.after] member like this.

<MyWidget>:
    canvas:
        Rectangle:
            source: 'mylogo.png'
            pos: self.pos
            size: self.size

How can I clear the canvas before I put the instructions?

like image 325
eviltnan Avatar asked Jan 18 '14 20:01

eviltnan


1 Answers

Use Clear:

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.lang import Builder

kv_string = '''
<MyWidget>:
    canvas:
        Color:
            rgb: 0.1, 0.6, 0.3
        Ellipse:
            size: self.size     
            pos: self.pos
        Clear
        Color:
            rgb: 0.6, 0.2, 0.1
        Ellipse:
            size: self.size     
            pos: self.center
'''

Builder.load_string(kv_string)

class MyWidget(Widget):
    pass

class TestApp(App):
    def build(self):
        return MyWidget()

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

In example above only one ellipse will be drawn since first one gets erased with Clear command. You can call it from Python using code like:

class SomeWidget(Widget):
    def some_method(self):
        self.canvas.clear()
        with self.canvas:
            # ...
like image 50
Nykakin Avatar answered Sep 30 '22 06:09

Nykakin