在Python Turtle中循环图像[关闭]

问题描述 投票:0回答:0

它应该循环显示不同的图像,但它不像我说的我不知道出了什么问题

这是应该循环遍历自定义海龟形状的代码,无论我做什么它都会中断

from turtle import Turtle, Screen
import turtle

a = 1

def k1():
    screen.onkey(None, 'd')
    global a
    a = a + 1
    print(a)
    return a
    if a == 2:
       charicter.shape('assets\charicters\criminal.gif')
       return a
    elif a == 3:
        charicter.shape('assets\charicters\priest.gif')
        return a
    elif a == 4:
        charicter.shape('assets\charicters\warrior.gif')
        return a
    elif a == 5:
        charicter.shape('assets\charicters\wizard.gif')
        return a
    
#the charicters
turtle.register_shape('assets\charicters\hunter.gif')
turtle.register_shape('assets\charicters\criminal.gif')
turtle.register_shape('assets\charicters\priest.gif')
turtle.register_shape('assets\charicters\warrior.gif')
turtle.register_shape('assets\charicters\wizard.gif')

charicter = turtle.Turtle()
charicter.shape('assets\charicters\hunter.gif')

text = turtle.Turtle()
text.hideturtle()
text.penup()
text.goto(-100, 300)
text.write('Enter to select a charicter', font=('arial', '18'))
 
text1 = turtle.Turtle()
text1.hideturtle()
text1.penup()
text1.goto(-100, 250)
text1.write('A, S, D, F, G To cycle through the charicters', font=('arial', '18'))

screen = Screen()
screen.setup(800,800)
screen.title('Rendering')
screen.tracer(False)

screen.onkey(k1, 'd')

screen.listen()
screen.tracer(True)
screen.title('Select a charicter')
screen.mainloop()

https://github.com/OPSPPESH/Shadowed-deeps) 如果您需要角色图片在资产中,这是完整内容+资产的存储库

python python-3.x turtle-graphics python-turtle
© www.soinside.com 2019 - 2024. All rights reserved.