Scatter
The Scatter in kivy is used for building interactive widgets that can be rotated, scaled and translated with two or more fingers on a multi-touch system.
A few points to be considered in the Scatter are shown below:
-
The scatter has its matrix transformation. It allows the user to translate, drag and rotate any widget.
-
The scatter children are positioned relative to the scatter, similar to RelativeLayout. While dragging the scatter, the position of the children doesn’t change. Only the position of the scatter changes.
-
The scatter size has no impact on the size of its children. To resize the scatter, you should use the scale that transforms the scatter and its children but does not change the size.
Below, we will be showing the implementation of the Scatter widget.
Implementation
The implementation is as follows:
Python File
# import kivy module
import kivy
from kivy.app import App
from kivy.lang import Builder
# If you want to work with the Scatter, you must include this library
from kivy.uix.scatter import Scatter
# Widgets are the elements of the GUI
from kivy.uix.widget import Widget
# It allows you to set relative coordinates for children.
from kivy.uix.relativelayout import RelativeLayout
# load the scatter.kv file
Builder.load_file('scatter.kv')
# widget class
class SquareWidget(Widget):
pass
# Scatter Class
class ScatterWidget(Scatter):
pass
# layout class
class ScatterLayout(RelativeLayout):
pass
# ScatterApp class
class ScatterApp(App):
def build(self):
return ScatterLayout()
ScatterApp().run()

You can also try this code with Online Python Compiler
Run Code
scatter.kv File
# Square to show scatter
<SquareWidget>:
size: 100, 100
canvas:
Color:
rgb: [34 / 255, 139 / 255, 34 /255]
Rectangle:
size: self.size
pos: self.pos
# Scatter properties
<ScatterLayout>:
canvas:
Color:
rgb: [0 , 0 , 1]
Rectangle:
size: self.size
pos: self.pos
ScatterWidget:
id: square_widget_id
SquareWidget:
Explanation
- First, we imported the required headers.
- Then we created three custom widgets, namely SquareWidget, ScatterWidget and ScatterLayout, leaving blank using pass.
- We inherited the subclass, namely ScatterApp, from the superclass App.
- Inside the subclass ScatterApp, we overrode the build function that returns the ScatterLayout Widget.
- The ScatterApp.run() builds the app, which returns the ScatterLayout widget.
- We created the scatter.kv file, which contains the layout of the widgets.
- We loaded the scatter.kv file using Builder.load_file(“scatter.kv”)
- The custom widgets are accessed using the angular braces(“<>”) in scatter.kv file.
- Each of the widgets contains attributes which specify the layout.
- The ScatterLayout widget contains the ScatterWidget widget as an attribute, and the ScatterWidget widget contains the SquareWidget widget as an attribute.
- The ScatterLayout forms the blue coloured outer layout, inside which the ScatterWidget is defined that contains the SquareWidget, which forms the green coloured square part inside it.
Output

FAQs
What is Kivy?
Kivy is an open-source platform-independent GUI development python library for developing applications.
What is the Scatter widget in Kivy?
The Scatter in kivy is used for building interactive widgets that can be rotated, scaled and translated with two or more fingers on a multi-touch system.
What is the widget in Kivy?
The widget in Kivy is the base building block of the GUI interface.
What is the root of Kivy?
The root inside a kv file refers to the parent with the angular brackets.
Conclusion
In this article, we have extensively discussed the Scatter in Kivy.
- We started with the basic introduction.
- We discussed the Kivy.
- We looked at what a Scatter is in Kivy.
-
We showed the implementation of the Scatter in Kivy.
We hope that this blog has helped you enhance your knowledge regarding Scatter in Kivy. If you would like to learn more, check out our articles on Open Source Python Libraries and Application Development in Python, Kivy Float Layout in Python, and Popular Python Libraries. Do upvote our blog to help other ninjas grow.
Head over to our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences, follow our guided paths, and crack product based companies Interview Bundle.
Happy Reading!