简体   繁体   English

vim python 龟窗口

[英]vim python turtle window

I'm on a Mac with macOS Mojave v. 10.14.3 .我在装有 macOS Mojave v. 10.14.3 的 Mac 上。 I'm using vim per professors edict.我正在按照教授法令使用 vim。 I learning python as part of a unix class.我在 unix 课程中学习 python。 My first lines in vim are:我在 vim 中的第一行是:

import turtle             # Allows us to use turtles
wn = turtle.Screen()      # Creates a playground for turtles
alex = turtle.Turtle()    # Create a turtle, assign to alex

alex.forward(50)          # Tell alex to move forward by 50 units
alex.left(90)             # Tell alex to turn by 90 degrees
alex.forward(30)          # Complete the second side of a rectangle

wn.mainloop()             # Wait for user to close window

These lines are copied from: How to Think Like a Computer Scientist: Learning with Python 3这些行复制自:如何像计算机科学家一样思考:使用 Python 3 学习

Doing w |做 w | !python % on the command line yields: !python % 在命令行上产生:

the window appears and immediately vanishes!窗口出现并立即消失!

with:和:

Traceback (most recent call last):
  File "turtle", line 2, in <module>
    wn = turtle.Screen()      # Creates a playground for turtles
  File "/usr/lib/python2.7/lib-tk/turtle.py", line 3553, in Screen
    Turtle._screen = _Screen()
  File "/usr/lib/python2.7/lib-tk/turtle.py", line 3569, in __init__
    _Screen._root = self._root = _Root()
  File "/usr/lib/python2.7/lib-tk/turtle.py", line 458, in __init__
    TK.Tk.__init__(self)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1823, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

I tried the same thing using ssh to my RPi (what we use for learning about the kernel) and got:我在我的 RPi 上使用 ssh 尝试了同样的事情(我们用来学习内核的)并得到:

the window appears and immediately disappears;窗口出现并立即消失; as above.如上。 I didn't copy the shell response;我没有复制 shell 响应; I wanted to try the following.我想尝试以下方法。

I then tried logging directly into the RPi with full 'windows' regalia after shutdown and tried the same script and the same command line entry and got:然后,我尝试在关机后使用完整的“windows” regalia 直接登录 RPi,并尝试使用相同的脚本和相同的命令行条目,并得到:

The same window problem with the addition of what appeared to be drawing on the window before disappearing.相同的窗口问题,在消失之前添加了似乎在窗口上绘制的内容。 Further:更远:

Traceback (most recent call):
   File "turtle", line 9, in <module>
     wn.mainloop()        # wait for user to close window
AttributeError: '_screen' object has no attribute 'mainloop'

I hope I'm not too through.我希望我没有太通过。
I'll not see the professor for another 2 weeks and possibly longer as I'm to have shoulder surgery.我还要再过 2 周甚至更长的时间才能见到教授,因为我要进行肩部手术。

Even today, Apple's Mac OS X by default supplies multiple versions of Python 2 (invoked as python at the command line) and no versions of Python 3. You should install your own Python 3 (typically invoked as python3 at the command line.)即使在今天,Apple 的 Mac OS X 默认提供多个版本的 Python 2(在命令行中作为python调用)并且没有 Python 3 版本。您应该安装自己的 Python 3(通常在命令行中作为python3调用)。

You can also make code this basic insensitive to the difference:您还可以使代码对差异不敏感:

import turtle  # Allows us to use turtles

wn = turtle.Screen()  # Creates a playground for turtles
alex = turtle.Turtle()  # Create a turtle, assign to alex

alex.forward(50)  # Tell alex to move forward by 50 units
alex.left(90)  # Tell alex to turn by 90 degrees
alex.forward(30)  # Complete the second side of a rectangle

wn.exitonclick()  # Wait for user to close (or click on) window

The above should run the same on either major version of Python.以上应该在 Python 的任一主要版本上运行相同。

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

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