简体   繁体   English

Python Turtle Graphics 窗口不显示任何内容

[英]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.因为它非常简单,所以它在我的 Windows PC 上运行良好,并且根本没有显示错误消息。

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.然而,在我的 Monterey M1 Macbook 上的 Pycharm 上,Python Turtle Graphics 窗口只显示黑屏和滚动条。

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

I think the application called python.app is something wrong.我认为名为 python.app 的应用程序有问题。 That's why I updated python with brew and re-installed Pycharm, but nothing has changed.这就是为什么我用 brew 更新了 python 并重新安装了 Pycharm,但没有任何改变。

Does anyone know how to fix this?有谁知道如何解决这一问题? Thank you.谢谢你。

have you tried to install the latest version of python?你试过安装最新版本的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.我尝试安装最新的 python 版本,它现在就像一个魅力。

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

I don't think it has anything to do with the M1 processor.我认为这与 M1 处理器无关。 I have an M1 processor and had the same problem.我有一个 M1 处理器并且有同样的问题。 My solution: Create a new project in Python.我的解决方案:在 Python 中创建一个新项目。 Previously configured interpreter Select Python 3.10 (the latest installed version).之前配置的解释器选择 Python 3.10(最新安装的版本)。 Click the button with the three dots ... Go to the directory of Python 3.10 (current version).单击带有三个点的按钮... 进入 Python 3.10(当前版本)的目录。 IDLE.app -> Contents -> MacOS and -> Select Python. IDLE.app -> 内容 -> MacOS 和 -> 选择 Python。 For me it looks like this:对我来说,它看起来像这样:

/Applications/Python 3.10/IDLE.app/Contents/MacOS/Python /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.更新解释器将有助于解决问题,就像它在我的 M1 Mac 中所做的那样,而无需创建新项目。 However, there are a few extra steps needed to make sure it's compatible with your M1 chip.但是,需要一些额外的步骤来确保它与您的 M1 芯片兼容。


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)下载最新的 Python 版本(确保下载链接标记为“macOS 64-bit universal2 installer” ,因为它将与您的 M1 Mac 完全兼容)
  2. After installing the interpreter, open Pycharm -> Preferences -> Project: [ Your Poject's Name ] -> Python Interpreter安装解释器后,打开 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..."单击 Python 解释器框旁边的选项按钮(齿轮按钮),然后选择“添加...”
  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)选择任何空文件夹(或创建一个)来存储您的解释器(我选择将其存储在“Personal Python Interp”文件夹中的 Documents 中)
  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" )对于“基本解释器:”,“选择带有三个点的按钮并粘贴/Applications/Python 3.10/IDLE.app/Contents/MacOS/Python ,然后按“确定”(重要提示:您的 Python 版本号可能不同,因此请更新将“Python 3.10”添加到“应用程序”中的 python 文件夹名称
  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如果有,请将您可能需要的任何 Python 包重新下载到此解释器上

The turtle screen should be now fixed!乌龟屏幕现在应该修复了! I hope this helped!我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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