ImportError: No module named Tkinter when importing swampy.TurtleWorld

后端 未结 1 1692
忘掉有多难
忘掉有多难 2021-01-28 19:44

I am using Python 3.4 and following along the book \"Think Python: how to think like a computer scientist\". I actually figured out this issue a week ago, but saved over the ori

1条回答
  •  后悔当初
    2021-01-28 20:19

    You're trying to run Python 2 code in Python 3 that loads Python 2 specific modules (Tkinter) and it's not going to work.

    The default TurtleWorld package is Python 2, but there is an unsupported Python 3 version from the Green Tea Press' Swampy: Installation Instructions page. Go to the Python 3 section at the bottom. You will either need to install this package manually or just keep it in your working directory and import it from there. (The instructions explain this.)

    Another alternative is to use the turtle module that comes with Python 3, as it's functionally similar for most turtle-related experiments. (I've answered TurtleWorld questions on SO using the Python turtle module.) For example:

    from turtle import Turtle, Screen
    
    bob = Turtle(shape="turtle")
    print(bob)
    bob.fd(100)
    bob.lt(90)
    bob.fd(100)
    
    screen = Screen()
    screen.exitonclick()
    

    0 讨论(0)
提交回复
热议问题