-
Book Overview & Buying
-
Table Of Contents
Kivy Cookbook
By :
We have already worked with shaders in this chapter, but now we will work with our own shaders. To show this, we will create an app with only the ShaderWidget.
We will use the preceding recipe Editing shaders to complete this recipe. Particularly, we will use the ShaderWidget class implemented there.
We will need a KV file and a Python file in this recipe. The KV file gives the size and position to the ShaderWidget, and the Python file will have our shader. Now, follow these steps:
In the KV file, define the ShaderWidget rule.
Add canvas for color, pos, and size:
<ShaderWidget>:
canvas:
Color:
rgb: 1, 0, 0
Rectangle:
pos: self.pos
size: self.sizeIn the Python file, import the usual Kivy packages.
Also import the RenderContext and StringProperty packages.
Define the header of Our shader.
Define Our shader.
Define ShaderWidget.
Call ShaderWidget with Our shader:
import kivy
kivy.require('1.9.0') # Code tested in...
Change the font size
Change margin width
Change background colour