Drawing with a turtle (python) using PyCharm

I am running the latest version of PyCharm Pro and trying to run the code below from a scratched file, but it does not work

import turtle

wn = turtle.Screen() 
alex = turtle.Turtle()
alex.forward(150)  
alex.left(90) 
alex.forward(75)

Not working, I mean that the window does not appear, but I see in the output

Process finished with exit code 0

Any idea

  • If it can be done with PyCharm
  • What am I missing in terms of configuration

Greetings

+4
source share
5 answers

I managed to find a way to do this using the code below.

The only drawback is that it closes the canvas after it is completed.

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 another idea on how to close the canvas, that would be awesome.

Thank,

Dani

+3
source

. , "".

turtle.done()

turtle.exitonclick()

!

+12

, , ( ):

turtle.exitonclick()

.

+1

" " , , . , :

import turtle

wn = turtle.Screen() 
alex = turtle.Turtle()
alex.forward(150)  
alex.left(90) 
alex.forward(75)

wn.mainloop()
0

. , , . exitonclick() .

import turtle

wn = turtle.Screen()    
alex = turtle.Turtle()
alex.forward(150)      
alex.left(90)     
alex.forward(75)    
wn.exitonclick()
0

All Articles