简体   繁体   中英

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.

import turtle

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

毛刺乌龟屏幕

There's a similar unresolved question on 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

Brutal fix.

Some combination of MacOS version, Python version and tkinter configuration create this issue.

I followed the steps in this SO answer .

However there is a small change, with MacOS Mojave 12.3, Python 3.8.13 must be installed. 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

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