Question: Python gui, I implemented a fire target 2D gui where the target ( a circle) is display in a random position each time the program

Python gui, I implemented a fire target 2D gui where the target ( a circle) is display in a random position each time the program opens. Now i'm having problems with the shot tracker while loop that way when the user hits the target the program stops and display a winning msg.

Code:

from animation import *

from graphics import *

from button import Button import random

def main():

# create animation window

win = GraphWin("Tiro al blanco", 640, 480, autoflush=False)

win.setCoords(-10, -10, 210, 155)

Line(Point(-10,0), Point(210,0)).draw(win)

win.setBackground("blue") # random generated x,y and radius for circle radius = 5 x = random.randint(30,150) y = random.randint(20,120) left = x - radius right = x + radius top = y + radius bottom = y - radius

# Below line for codes for drawing circle head = Circle(Point(x, y), radius) # set center and radius head.setFill("red") head.draw(win)

#mensajes

message = Text(Point(10,20), "NICE WORK, YOU HIT IT!")

for x in range(0, 210, 50):

Text(Point(x,-5), str(x)).draw(win)

Line(Point(x,0), Point(x,2)).draw(win)

angle, vel = 1.0, 1.0

height = 0.0

while True:

# interact with the user

inputwin = InputDialog(angle, vel, height)

choice = inputwin.interact()

inputwin.close()

if choice == "Quit": # loop exit

break

# projectile

angle, vel, height = inputwin.getValues()

shot = ShotTracker(win, angle, vel, height)

while 0 <= shot.getY() and -10 < shot.getX() <= 210:

shot.update(1/30)

update(90)

if shot.getX() >= right and shot.getX() <= left and shot.getY() >= bottom and shot.getY() <= top:

message.draw(win)

break;

else:

message.undraw()

# message.undraw()

win.close()

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!