Skip to content

Instantly share code, notes, and snippets.

@Zen-CODE
Last active December 22, 2015 00:29
Show Gist options
  • Save Zen-CODE/6389737 to your computer and use it in GitHub Desktop.
Save Zen-CODE/6389737 to your computer and use it in GitHub Desktop.
Demo of Stencil behavior
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
Builder.load_string("""
<CustomLabel>:
canvas.before:
StencilPush
Rectangle:
pos: 0, 0
size: 200, 200
StencilUse
#canvas.after:
Color:
rgba: 0, 0, 1, 0.5
Rectangle:
pos: self.pos
size: self.size
StencilUnUse
StencilPop
Color:
rgba: 0, 1, 0, 0.5
Rectangle:
pos: self.pos
size: self.size
""")
class CustomLabel(Label):
pass
class TestApp(App):
def build(self):
root = FloatLayout()
lbl = CustomLabel(text="Test")
root.add_widget(lbl)
return root
if __name__ == "__main__":
TestApp().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment