繁体   English   中英

如何在 Pythonista IDE 中正确使用 python turtle() 函数?

[英]How do I properly use the python turtle() function in the Pythonista IDE?

为了方便起见,我最近切换到 iPad,而我的一个在 PyCharm 中运行良好的脚本在 Pythonista 中崩溃了。 我收到一条错误消息,说“海龟”对象没有“形状”属性。 (抱歉格式不正确)。 这是以下代码的一部分:

 ### Import required library 

import turtle

import scene

sc = turtle.Screen()

sc.title("Snake Game")

sc.bgcolor("#FFFFFF")

sc.setup(width=1000, height=600)

def up():
    print("up")

def down():
    print("down")

def left():
    print("left")

def right():
    print("right")

snake_head = turtle.Turtle()

snake_head.speed(0)

snake_head.shape("square")

snake_head.color("black")

snake_head.shapesize(stretch_wid=1, stretch_len=1)

snake_head.penup()

snake_head.goto(200, 200)

#Keyboard Bindings

sc.listen()

sc.onkeypressup(up_move, "W")

sc.onkeypressdown(down_move, "S")

sc.onkeypressleft(left_move, "A")

sc.onkeypressright(right_move, "D")

turtle.done()

据我所知, turtle.shape()方法在 Pythonista 中根本不起作用。 如果您查看 Pythonista 文档,它确实在 Turtle 模块下显示为有效方法,因此我认为我们可以假设它正在开发中。

我看到的另一个问题是,即使你turtle.shape()了对turtle.shape()的引用,你也会遇到没有键盘来使用你的键映射的问题,这会导致你更加悲伤,因为你将不得不想出一个替代输入法。

Pythonista 是适用于 iOS/iPadOS 的出色应用程序,但是在从桌面操作系统上使用 python 迁移时,有很多东西根本无法以相同的方式工作,虽然有可能让这样的东西工作,但 Pythonista 是很多的更适合在您的设备上自动执行任务,而不是像您在这里尝试做的那样使用图形进行操作。 我会说你最好的办法是为你的台式机/笔记本电脑保存这种 Python 编程,并更多地使用 Pythonista 来编写小型自动化脚本。

暂无
暂无

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

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