Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
turtle window not showing
#1
Hi,

I am new trying to learn python.

For the turtle, I actually copied the following code and tried to run on Pycharm community 2020 1.1 version just to learn.
The code is from google and actually run by someone:
import turtle
def main():
wn = turtle.Screen()
alex = turtle.Turtle()
alex.forward(150)
alex.left(90)
alex.forward(75)
wn.exitonclick()

But when I clicked run, as seen from you tube the python graphic (or canvas or window, however you call it) will pop up and draw whatever code, but in my case it didn't pop up at all.
It just showed:
'Process finished with exit code 0'
I tried different codes but the window still not popping up.
Can I know what is missing from the installation?
Please advise, appreciate your help.
Reply
#2
First you need to import the module, then after defining your code you need to allow it to execute.
See the code example below:
import turtle

def main():
    wn = turtle.Screen()
    alex = turtle.Turtle()
    alex.forward(150)
    alex.left(90)
    alex.forward(75)
    wn.exitonclick()
if __name__=='__main__':
    main()
"Often stumped... But never defeated."
Reply
#3
Got it thanks.
Reply
#4
Also @yokeloonlo01 please use proper coding tags in future threads & posts
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a way to call and focus any popup window outside of the main window app? Valjean 6 1,613 Oct-02-2023, 04:11 PM
Last Post: deanhystad
  Turtle Graphics - Screen & Window Sizing jerryf 1 773 Feb-09-2023, 08:02 PM
Last Post: jerryf
  Pyspark Window: perform sum over a window with specific conditions Shena76 0 1,132 Jun-13-2022, 08:59 AM
Last Post: Shena76
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,129 Feb-06-2019, 01:25 AM
Last Post: woooee
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 5,544 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020