Relation

Adding Simple Graphics

To add graphics, we will need to create a .kv file to define the look and feel of the PongGame class. Make a file called pong.kv (note the .kv extension) in the same directory. Then, add the following contents.

#:kivy 1.0.9 <PongGame>: canvas: Rectangle: pos: self.center_x - 5, 0 size: 10, self.height Label: font_size: 70 center_x: root.width / 4 top: root.top - 50 text: "0" Label: font_size: 70 center_x: root.width * 3 / 4 top: root.top - 50 text: "0"

At this point, you should see a vertical bar in the middle and two zeroes where the player scores will be displayed.

IMPORTANT NOTE: The name of the kv file must match the name of the app, i.e. pong.kv for PongApp (the part before the App ending).

0

1

Updated 2021-09-03

Tags

Python Programming Language

Data Science

Learn After