Reputation: 1250
I am learning Python (v 3.7) on a Mac using PyCharm. As I practice using the turtle
library, the program runs without error, outputs the correct graphics, but then the graphics screen disappears immediately after the code completes runnning. Adding time.sleep(5)
at the end of my program persists it and also shows that the focus changed from PyCharm to a Python program menu (which I can't find or turn on in the hope of keeping running).
When I use Thonny, the output persists, so I can check my work. How can I make it persist in PyCharm?
Upvotes: 0
Views: 1953
Reputation: 41872
A well-structured Python turtle program will end with a call to mainloop()
or one of its variants (exitonclick()
, done()
) This turns control over to the underlying tkinter event handler which will keep your window open, awaiting user events. Without this, the program simply ends and the window closes.
You don't need time.sleep()
nor input("Press Enter to continue...")
. Some Python programming environments clash with mainloop()
but even those tend to disable it behind the scenes so the same code works everywhere.
Upvotes: 1
Reputation: 41
First, do not use PyCharm to test. If you like it, more power to you, but personally, I have had many issues with output and PyCharm. Learn the command line, since you are using Mac. CodeAcacdemy and LinuxJournery have really good resources on that subject. Second, if you are still having issues, please reinstall trutle, Python 3.7 (there were some issues wiht it displaying on Mac), and macOS itself. Have a great day!
https://linuxjourney.com/ https://www.codecademy.com/learn/learn-the-command-line Problems getting pygame to show anything but a blank screen on Macos Mojave
Upvotes: 0