Chapter 4. Creating Games and Graphics

In this chapter, we will cover the following topics:

  • Using IDLE3 to debug your programs
  • Drawing lines using a mouse on a Tkinter Canvas
  • Creating a bat and ball game
  • Creating an overhead scrolling game

Introduction

Games are often a great way to explore and extend your programming skills as they present an inherent motivating force to modify and improve your creation, add new features, and create new challenges. They are also great for sharing your ideas with others, even if they aren't interested in programming.

This chapter focuses on using the Tkinter Canvas widget to create and display objects on screen for the user to interact with. Using these techniques, a wide variety of games and applications can be created that are limited only by your own creativity.

We also take a quick look at using the debugger built into IDLE, a valuable tool for testing and developing your programs without the need to write extensive test code.

The first example demonstrates how we can monitor and make use of the mouse to create objects and draw directly on the Canvas widget. Next, we create a bat and ball game, which shows how the positions of objects can be controlled and how interactions between them can be detected and responded to. Finally, we take things a little further and use Tkinter to place our own graphics onto the Canvas widget to create an overhead view treasure hunt game.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.166.98