将python海龟图形编号链转换为名称
Convert python turtle graphics number chain to name
我一直在制作一个简单的列表函数来添加一堆图像供海龟使用,但是当 运行 时我一直收到此错误:_tkinter.TclError: couldn't open "<turtle.Turtle object at 0x000001C20E311D90>_1.gif": no such file or directory
这是我的代码。
for i in Citygroups:
i.up()
wn.addshape(str(i)+'_1.gif')
wn.addshape(str(i)+'_2.gif')
wn.addshape(str(i)+'_3.gif')
所以我想知道是否有办法将<turtle.Turtle object at 0x000001C20E311D90>
转换为乌龟的名字。 (即:City_l1)
您可以使用字典来存储 Turtle 对象并将键用作名称:
citygroups = dict()
citygroups["City_L1"] = t.Turtle()
# and so on...
for turtle_name, turtle_object in citygroups.items():
turtle_object.up()
wn.addshape(f"{turtle_name}_1.gif")
wn.addshape(f"{turtle_name}_2.gif")
wn.addshape(f"{turtle_name}_3.gif")
我一直在制作一个简单的列表函数来添加一堆图像供海龟使用,但是当 运行 时我一直收到此错误:_tkinter.TclError: couldn't open "<turtle.Turtle object at 0x000001C20E311D90>_1.gif": no such file or directory
这是我的代码。
for i in Citygroups:
i.up()
wn.addshape(str(i)+'_1.gif')
wn.addshape(str(i)+'_2.gif')
wn.addshape(str(i)+'_3.gif')
所以我想知道是否有办法将<turtle.Turtle object at 0x000001C20E311D90>
转换为乌龟的名字。 (即:City_l1)
您可以使用字典来存储 Turtle 对象并将键用作名称:
citygroups = dict()
citygroups["City_L1"] = t.Turtle()
# and so on...
for turtle_name, turtle_object in citygroups.items():
turtle_object.up()
wn.addshape(f"{turtle_name}_1.gif")
wn.addshape(f"{turtle_name}_2.gif")
wn.addshape(f"{turtle_name}_3.gif")