简体   繁体   English

Python 乌龟图形在 MacOS Mojave 12.3 上不工作

[英]Python turtle graphics are not working on MacOS Mojave 12.3

I'm writing a python program using turtle graphics on When the turtle window opens up it is glitching and blinking but now showing any graphics.我正在编写一个使用海龟图形的 python 程序当海龟 window 打开时,它会出现故障和闪烁,但现在显示任何图形。

import turtle

turtle.up()
turtle.write("hello world")
turtle.done()

毛刺乌龟屏幕

There's a similar unresolved question on reddit . reddit上有一个类似的未解决问题。

I'm not sure what is wrong and how to fix it.我不确定哪里出了问题以及如何解决。

MacOS Mojave 12.3
Python 3.10.6
PythonTurtle == 0.3.2

Edit: This snippet works on ubuntu编辑:此片段适用于 ubuntu

Brutal fix.残酷的修复。

Some combination of MacOS version, Python version and tkinter configuration create this issue. MacOS 版本、Python 版本和 tkinter 配置的某些组合会导致此问题。

I followed the steps in this SO answer .我遵循了这个SO answer中的步骤。

However there is a small change, with MacOS Mojave 12.3, Python 3.8.13 must be installed.但是有一个小的变化,对于 MacOS Mojave 12.3,必须安装 Python 3.8.13。 SO answer所以回答

So the updated steps are below.所以更新的步骤如下。

brew install tcl-tk
env \
  PATH="$(brew --prefix tcl-tk)/bin:$PATH" \
  LDFLAGS="-L$(brew --prefix tcl-tk)/lib" \
  CPPFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PKG_CONFIG_PATH="$(brew --prefix tcl-tk)/lib/pkgconfig" \
  CFLAGS="-I$(brew --prefix tcl-tk)/include" \
  PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I$(brew --prefix tcl-tk)/include' --with-tcltk-libs='-L$(brew --prefix tcl-tk)/lib -ltcl8.6 -ltk8.6'" \
  pyenv install 3.8.13

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

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