I have my own code below, and would you let me know how to change as follow abov
ID: 3718773 • Letter: I
Question
I have my own code below, and would you let me know how to change as follow above information? it is related to python3
Problem 2 (50 XP). Modify the Etch class in EtchASketch.py so that the turtle fills with color by pressing on the keyboard key "f". Filling with color requires begin _fill0 and end fill) but make sure that a single callback function handles both with the press of the "f" key. Do not worry about the actual color; it will default to the current color the turtle has. [Hint: use a self.isFilling flag, set it to false and alternate its value upon each press of the "f" key]Explanation / Answer
here is your modified code :---------------->>>>>>>>>>>..
from turtle import Turtle, mainloop
class Etch(Turtle):
def __init__(self):
super().__init__() #calls the init of Turtle
self.screen = self.getscreen()
self.isFill = False
self.color('blue')
self.shape('turtle')
self.pensize(2)
self.distance = 5
self.turn = 10
self.screen.onclick(self.Aim)
self.screen.onkey(self.fwd, "Up")
self.screen.onkey(self.bkwd, "Down")
self.screen.onkey(self.leftTurn, "Left")
self.screen.onkey(self.rightTurn, "Right")
self.screen.onkey(self.colorRed, "r")
self.screen.onkey(self.colorBlue, "b")
self.screen.onkey(self._up, "u")
self.screen.onkey(self._down, "d")
self.screen.onkey(self.fillColor,"f")
self.speed("fastest")
self.screen.listen()
self.main()
def _up(self):
self.up()
def fillColor(self):
if self.isFill == False:
self.isFill = True;
self.begin_fill()
else:
self.isFill = False;
self.end_fill()
def Aim(self,x,y):
heading = self.towards(x,y)
self.setheading(heading)
def _down(self):
self.down()
def colorRed(self):
self.color("red")
def colorBlue(self):
self.color("blue")
def fwd(self):
self.forward(self.distance)
def bkwd(self):
self.backward(self.distance)
def leftTurn(self):
self.left(self.turn)
def rightTurn(self):
self.right(self.turn)
def main(self):
mainloop()
#A way of running the program with an instance of the object Etch
if __name__ == '__main__':
etch = Etch()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.