Ibrahim Omar - Kivy Interactive Applications and Games in Python PDF
Ibrahim Omar - Kivy Interactive Applications and Games in Python PDF
proportional ("percentages" of the total size of size_ A proportion from Yes No y, top or Fixed Yes, but don't Yes
coordinates the window) rather than fixed hint_x 0 to 1 or None, center_y number use y, top or
coordinates (exact pixels).[ 10 ] size_ indicating width of center_y in
hint_y (size_ hint_x) or pixels. pos_hint
size_hint size_hint: .4, .3
height (size_
pos_hint: pos_hint: {'right': 1, 'y': 0}
hint_y). Graphics – the Canvas Chapter 2
{'x': 0, 'top':
pos_hint Dictionary with Yes No
1} Kivy is a set of drawing instructions
one x-axis key (x,
pos_hint: would align a widget in the Canvas that define the graphical
center_x, or right)
{'center_x':. middle no matter the size of the representation of Widget .
and one y-axis
5, window. coordinate the place in which we draw.All the
key (y, center_y,
'center_y':.5 space Kivy widgets share the same
or top). The
} coordinate space, and a Canvas
values are
pos: root.x, we should have used: x: 0 top: instance, the instructions to draw
proportions from
root.top - root.height on it. A coordinate space is not
0 to 1.
self.height restricted to the size of the
size A pair w, h: w Yes, but Yes
window or the application screen,
The properties x, center_x, right, y, center_y, and h indicating set
which means that we can draw
and top always specify fixed coordinates fixed width and size_
outside of the visible area.
(pixels), and not proportional ones. If we want height in pixels. hint:
to use proportional coordinates, we have to be (None,
Understanding the canvas Chapter 2
inside a Layout (or an App) and use the None)
pos_hint property. • The coordinate space refers to the place in
width Fixed number of Yes, but Yes
pixels. set which we draw, which is not
Drawing basic shapes 2 Chapter 2 size_ restricted to the windows size
Understanding the canvas Chapter 2 (cont) Drawing basic shapes Chapter 2 (cont) LAYOUT 3 (cont)
make sure that the coordinate space is in its from the pos and size properties of Widget, GridLayout Organizes widgets in a grid. You
original state since they belong to have to specify at least one of
after modifying it with the graphics instructions. the VertexInstruction base class. All the values two properties – cols (for
A Widget is also a place marker (with its to specify the columns) or rows (for rows).
position and size), properties of the vertex instructions are given in
BoxLayout Organizes widgets in one row or
but not necessarily a placeholder. The fixed values.
one column depending on
instructions of the
whether the value of the
canvas of a widget are not restricted to the float layout orientation property is horizontal
specific area of or vertical.
the widget but to the whole coordinate space. We can also force a Layout to use fixed values,
but there can be conflicts if we are StackLayout Similar to BoxLayout, but it goes
not careful with the properties. If we use any to the next row or column when
Drawing basic shapes Chapter 2
Layout ; pos_hint and size_hint take it runs out of space. There is
The vertex instructions inherit from the priority. If we want to use fixed positioning more flexibility to set the
VertexInstruction base properties ( pos , x , center_x , right , orientation. For example, rl-bt
class, and allow us to draw vector shapes in the y , center_y , top ), we have to ensure that we organizes the widgets in
coordinate space. are not using the pos_hint property. right-to-left, bottom-to-top order.
The context instructions (Color, Rotate, Second, if we want to use the size , height , or Any combination of lr (left to
Translate, and Scale) width properties, then we need to right), rl (right to left), tb (top to
inherit from the ContextInstruction base class, set a None value to the size_hint axis we want bottom), and bt (bottom to top)
and let us apply to use with absolute values.[ 13 ] is allowed.
transformations to the coordinate space ScatterLayo Works in a similar manner to
context. By coordinate space LAYOUT 3 ut RelativeLayout but allows
context, we mean the conditions in which the multitouch gesturing for rotating,
Layout Details
shapes (specified in the scaling, and translating. It is
vertex instructions) are drawn in the coordinate FloatL Organizes the widgets with slightly different in its
space. ayout proportional coordinates by the implementation, so we will
Basically, vertex instructions are what we draw size_hint and pos_hint properties. review it later on.
and context instructions affect The values are numbers between 0
PageLayout Stacks widgets on top of each
where and how we draw. and 1, indicating a proportion to the
other, creating a multipage
This means that we cannot use the size_hint or window size.
effect that allows flipping of
pos_hint properties as we did
Relativ Operates in the same way that pages using side borders. Very
with the widgets in Chapter 1, GUI Basics –
eLayou FloatLayout does, but the positioning often, we will use another layout
Building an Interface. However, we can
t properties (pos, x, center_x, right, y, to organize elements inside
use the properties of self to achieve similar center_y, top) are relative to the each of the pages, which are
results (Line 18 and 19). Layout size and not the window size. simply widgets.
Rectangle is a good starting point because it
resembles the way we set properties Anchor The AnchorLayout aligns its
in widgets. We just have to set the pos and size layout children to a border (top,
properties. bottom, left, right) or center.
The pos and size properties of the vertex
instructions are different