1 / 17

Paddle Ball!

Paddle Ball!. We are going to make a “paddle ball” game. Before we do, we need to learn a few concepts. One of the biggest new concepts we will learn is called Object Orientation

jsloan
Télécharger la présentation

Paddle Ball!

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Paddle Ball!

  2. We are going to make a “paddle ball” game • Before we do, we need to learn a few concepts. One of the biggest new concepts we will learn is called Object Orientation • I have typed in the notes section of these slides, so for more information, please read the notes. Either View tab Notes page or…select the notes button at the bottom of the slide (if not in a slideshow)

  3. Drawing Shapes Making shapes using tkinter

  4. Using tkinter • Tkinter is a graphics module (like time, turtle, random…) • It is designed to work faster and better than the turtle module, which is designed to teach and practice using graphics (it’s basic). • Just like the time, random, and turtle modules, we have to import it before using.

  5. We need a canvas! Import tkinter: from tkinter import * tk = Tk( ) canvas = Canvas(tk, width=500, height = 500) canvas.pack( )

  6. Let’s make a box • We are going to begin by making a box ( a rectangle) • Now that we have a canvas, we will use a create_polygon functionwhich will draw a shape using parameters. • If a triangle uses 6 parameters:canvas.create_polygon(10, 10, 10, 60, 50, 35) • How many parameters do you think a rectanglewill use?

  7. Get rect[angle] newb  • That was for Cole & Dustin • Begin by creating a canvas to draw our rectangle on: fromtkinterimport* tk = Tk( ) canvas = Canvas(tk, width = 500, height = 500) canvas.pack( ) canvas.create_rectangle(10, 10, 50, 300) Coordinates for top left and bottom right corners

  8. Plain rectangles are boring • Let’s add some color by filling them in. Same code as before, but with one modification: canvas.create_rectangle(10, 10, 50, 300. fill = ‘green’) Now what has happened? Yes! A green rectangle.

  9. Pick a color, any color We can use the color selector (just like in Word) to select a color to fill our rectangle with. This is called the colorchooser Add to your code: (before the create rectangle) colorchooser.askcolor( )

  10. Use the color chooser in fill c = colorchooser.askcolor( ) canvas.create_rectangle(10, 10, 50, 300, fill=c[1]) * When the color is selected, a tuple is created with the red, green, and blue value amounts as well as the hexadecimal value for all three. The [1] index selects the hexadecimal value.

  11. More color options! • We can change the color of our object by configuring it. canvas.itemconfig(object, fill = ‘color’) • Our object is 1, because it is the object ID • We could give our shape a variable name and use that as well.

  12. What we can also change: fill = ‘color’ outline = ‘color’ * The outline and fill color do not have to be the same colors

  13. Arcs • Arc – a segment of the circumference of a circle • tkinter actually draws an arc inside of a rectangle. • When we create an arc, we use coordinates just like a rectangle. • We also use style and extent arguments

  14. Noah’s Arc Joakim Noah – Chicago Bulls

  15. 1st set of coordinates (10, 10) 2nd set of coordinates (200, 100) Extent – the degrees of the angle of the arc Style – its an arc

  16. Creating an arc Canvas.create_arc(10, 10, 200, 100, extent = 180, style = ARC

  17. Arc angle measurements tkinter considers 360o as the same as 0o, For a full circle, we’ll use 359o

More Related