I'm running the latest PyCharm Pro version and trying to run the below code from a scratch file but it doesn't seem to work
import turtle
wn = turtle.Screen()
alex = turtle.Turtle()
alex.forward(150)
alex.left(90)
alex.forward(75)
By not working I mean, no window is popping out however I do see in the output saying
Process finished with exit code 0
Any idea
Cheers
Turtle() # create a turtle named alex alex. forward(150) # tell alex to move forward by 150 units alex. left(90) # turn by 90 degrees alex. forward(75) # complete the second side of a rectangle if __name__ == "__main__": main() input("Press RETURN to close.
To try it yourself, follow the PyCharm installation instructions, then type some turtle graphics code, as in the example above. Finally, from the Run menu, choose Start Live Turtle. You should see a preview of your turtle graphics.
I ran into the same problem. Turns out the solution is in the "turtle" module.
You want to end with
turtle.done()
or
turtle.exitonclick()
Enjoy!
I managed to find out a way of doing it by using the below code.
The only downside is that it does close the canvas once it finished.
def main():
wn = turtle.Screen() # creates a graphics window
alex = turtle.Turtle() # create a turtle named alex
alex.forward(150) # tell alex to move forward by 150 units
alex.left(90) # turn by 90 degrees
alex.forward(75) # complete the second side of a rectangle
if __name__ == "__main__":
main()
If anyone has a different idea on how to not close the canvas that will be awesome.
Thanks,
Dani
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With