简体   繁体   中英

How to persist Python turtle graphics screen

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM