(Solved) : Week Learned Draw Basic Geometric Shapes Python Tkinter Use Knowledge Develop Simple Slot Q35604560
This week you learned how to draw basic geometric shapes withPython and TKInter.
Use this knowledge to develop a simple slot machine game:
- show 3 ‘slots’ (squares) in a horizontal row
- show a ‘Play’ button below the slots
- when the user clicks the Play button, display a randomly-chosenshape in each slot, choosing from these – square, circle,triangle
- Fill each shape with a color – it’s ok to hard-code one colorper shape
- if all 3 slots show the same shape, display a ‘Winner!’ messagebelow the Play button
- Define a function for creating each shape type
- Your functions should accept a parameter (or parameters) thatidentify where the shape should be drawn,
- Rectangle objects have properties you can use to inform yourdrawing functions:
r = Rectangle(Point(10,10), Point(90,90))print(r.p1,r.p2) # print upper_left & lower rightprint(r.getCenter()) # print center point of rectangle
- You can use this code to get started:
from graphics import *import randomwin = GraphWin(“Slot Machine”,600,600)# one-time definition of variables and functions can be herewhile True: p = win.getMouse() print(“You clicked”, p.getX(), p.getY()) # code that should execute with each mouse click should be here # this code generates a random number between 0 – 2 choice = random.randrange(3)
- Consider what Python data structures you can use to keep trackof which shapes are displayed
- Clear previously drawn shapes each time the ‘Play’ button isclicked,
- add support for more shapes – e.g. oval, diamond, crescentmoon, smiley face
- add support for different color combinations – e.g. red square,blue square, etc.
This assignment doesn’t require you to clear shapes beforedrawing new ones. But the user experience is better if you do. Howcan you do that?
TKinter graphics objects all support anundraw() method, as in this example:
s = Circle(Point(100,100), 30)s.draw(win)# some other codes.undraw()
To use this approach, your program should keep track ofgenerated shapes and undraw() them when re-starting the ‘Play’step.
HW 8 Rubric
Jackpot Spin! Show transcribed image text Jackpot Spin!