简体   繁体   中英

Python Turtle Graphics window shows nothing

I think my code is nothing wrong. Because it's very simple, it worked very well on my Windows PC, and shows no error message at all.

from turtle import Turtle, Screen

turtle = Turtle()
screen = Screen()

screen.exitonclick()

However, on Pycharm on my Monterey M1 Macbook, the Python Turtle Graphics window shows nothing but black screen and scroll bars.

带有黑屏和滚动条的 Python Turtle 图形窗口

I think the application called python.app is something wrong. That's why I updated python with brew and re-installed Pycharm, but nothing has changed.

Does anyone know how to fix this? Thank you.

have you tried to install the latest version of python? cause I'm facing the same problem earlier. I tried to install the latest python version and it just works like a charm now.

将pycharm中的interprete pycharm解释器r改为3.9或3.10。

I don't think it has anything to do with the M1 processor. I have an M1 processor and had the same problem. My solution: Create a new project in Python. Previously configured interpreter Select Python 3.10 (the latest installed version). Click the button with the three dots ... Go to the directory of Python 3.10 (current version). IDLE.app -> Contents -> MacOS and -> Select Python. For me it looks like this:

/Applications/Python 3.10/IDLE.app/Contents/MacOS/Python

Then it works for me.

Updating the interpreter will help fix the issue as it did in my M1 Mac and without needing to make a new project. However, there are a few extra steps needed to make sure it's compatible with your M1 chip.


Quick Steps:

  1. Download the latest Python version (Make sure the download link is labeled as "macOS 64-bit universal2 installer" as it'll be fully compatible with your M1 Mac)
  2. After installing the interpreter, open Pycharm -> Preferences -> Project: [ Your Poject's Name ] -> Python Interpreter
  3. Click the Options button (Gear Button) next to the Python Interpreter Box and select "Add..."
  4. Make sure "New Environment" is selected
  5. Select any empty folder (or make one) to store your interpreter (I chose to store it in Documents in the "Personal Python Interp" folder)
  6. For "Base Interpreter: ", "select the button with the three dots and paste /Applications/Python 3.10/IDLE.app/Contents/MacOS/Python , then press "OK" ( IMPORTANT: Your Python version number may be different so update the "Python 3.10" to the python folder name found in "Applications" )
  7. Check both boxes for "Inherit global site-packages" and "Make available to all projects" ( UNLESS you have specific interpreters for other projects)
  8. If any, re-download any Python Packages you may need onto this interpreter

The turtle screen should be now fixed! I hope this helped!

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