Canvas — Kivy v1.0.1-dev documentation

# Canvas

The `Canvas` is the root object used for drawing by a `Widget`. Check module documentation for more information about the usage of Canvas.

class `kivy.graphics.instructions.` `Instruction`(**kwargs)

  Bases: `object`

  Represent the smallest instruction available. This class is for internal usage only, don’t use it directly.

class `kivy.graphics.instructions.` `InstructionGroup`(**kwargs)

  Bases: `kivy.graphics.instructions.Instruction`

  Group of `Instruction`. Add the possibility of adding and removing graphics instruction.

  `add`(Instruction c)

    Add a new `Instruction` in our list.

  `clear`()

    Remove all the `Instruction`

  `get_group`(str groupname)
    Return a generator with all the `Instruction` from a specific
      group name.
  `insert`(int index, Instruction c)

    Insert a new `Instruction` in our list at index.

  `remove`(Instruction c)

    Remove an existing `Instruction` from our list.

  `remove_group`(str groupname)

    Remove all `Instruction` with a specific group name.

class `kivy.graphics.instructions.` `ContextInstruction`(**kwargs)

  Bases: `kivy.graphics.instructions.Instruction`

  A context instruction is the base for creating non-display instruction for Canvas (texture binding, color parameters, matrix manipulation...)

class `kivy.graphics.instructions.` `VertexInstruction`(**kwargs)

  Bases: `kivy.graphics.instructions.Instruction`

  `source`

    Property for getting/setting a filename as a source for the texture.

  `tex_coords`

    Property for getting/setting texture coordinates.

  `texture`

    Property for getting/setting the texture to be bound when drawing the vertices.

class `kivy.graphics.instructions.` `Canvas`(**kwargs)

  Bases: `kivy.graphics.instructions.CanvasBase`

  Our famous Canvas class. Use this class for add graphics or context instructions to use when drawing

  Note

  The Canvas support “with” statement.

  Usage of Canvas without “with” statement:

      self.canvas.add(Color(1., 1., 0))
      self.canvas.add(Rectangle(size=(50, 50)))

  Usage of Canvas with the “with” statement:

      with self.canvas:
          Color(1., 1., 0)
          Rectangle(size=(50, 50))

  `add`(Instruction c)
  `after`

    Property for getting the after group.

  `before`

    Property for getting the before group.

  `draw`()

    Apply the instruction on our window.

  `remove`(Instruction c)

class `kivy.graphics.instructions.` `RenderContext`(*args, **kwargs)

  Bases: `kivy.graphics.instructions.Canvas`

  The render context store all the necessary information for drawing, aka:

  - the fragment shader
  - the vertex shader
  - the default texture
  - the state stack (color, texture, matrix...)