[Python] How to make listen() wait between inputs?

Discussão em 'Python' iniciado por Stack, Novembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    So I have a movement script for my turtle (called mc)

    from turtle import *

    wn = Screen()
    MC=Turtle()

    def w():
    mc.shape(FFM1)
    mc.forward(40)
    mc.shape(FFM2)
    mc.forward(40)
    mc.shape(FFS)

    def s():
    mc.shape(BFM1)
    mc.bk(40)
    mc.shape(BFM2)
    mc.bk(40)
    mc.shape(BFS)

    def a():
    mc.shape(LFM1)
    mc.setx(mc.xcor() - 40)
    mc.shape(LFM2)
    mc.setx(mc.xcor() - 40)
    mc.shape(LFS)

    def d():
    mc.shape(RFM1)
    mc.setx(mc.xcor() + 40)
    mc.shape(RFM2)
    mc.setx(mc.xcor() + 40)
    mc.shape(RFS)

    wn.onkey(w, "w")
    wn.onkey(s, "s") # "Back"
    # ^^^^
    wn.onkey(a, "a")
    wn.onkey(d, "d")

    listen()
    mainloop()


    This works but if I press, for example, d more than once while turtle is still moving it carries on moving however when it stops it teleports back to where it should have gone from the first move.

    I've tried putting a time.sleep(2) in the function but it doesn't do anything and just freezes the turtle for two seconds and then carries on breaking

    Continue reading...

Compartilhe esta Página