Graphics instructions don't seem to be designed to have multiple parents, yet there is no check preventing this.
Author: gottadiveintopythonCreated Nov 28, 2025Updated May 28, 2026
LabelsComponent: graphicsType: FeaturePriority: Low
Software Versions
- Python: CPython 3.13
- OS: Linux Mint
- Kivy: 91dc72d7cc979f37e2b1344bf9edd5db7957bbd1 (master branch around Sep 2025)
- Kivy installation method: development install (
$ pip install -e ".[dev,full]")
Describe the bug
The Instruction class has an attribute that holds its parent.
To me, this implies that graphics instructions cannot be shared between multiple parents.
However, when you run the following code, no error or warning is raised:
import kivy.core.window # Ensures OpenGL context exists. This doesn't seem to matter, though.
from kivy.graphics import InstructionGroup, Color
g1 = InstructionGroup()
g2 = InstructionGroup()
color = Color()
g1.add(color)
g2.add(color)I have made this mistake a couple of times when working with stencil instructions:
with canvas:
StencilPush()
shared = RoundedRectangle(...)
StencilUse()
...
StencilUnUse()
canvas.add(shared)
StencilPop()I haven't encountered any incorrect rendering results from this, though. Still, I feel that some kind of check—or at least documentation—is neccesarry.
Additional context
InstructionGroup.add() calls Instruction.radd()
which calls Instruction.set_parent()
which performs no check.
Source: kivy/kivy