Python Forum
[Turtle]Need help with moving a square on key press
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Turtle]Need help with moving a square on key press
#3
Screen.tracer(0)#turns off the screen updates has stopped the screen updates, i removed this line.
The while loop you created is not needed, Screen.mainloop() takes care of it.
I removed the function move and moved the block movement code directly into the key events.
Full code
import turtle

# screen
Screen = turtle.Screen()
Screen.title("Block")
Screen.bgcolor("white")
Screen.setup(width=1280, height=720)

# game
Block = turtle.Turtle()
Block.speed(0)  # no slow down with animation speed
Block.shape("square")  # shape
Block.color("black")  # color not colour
Block.penup()  # stops drawing
Block.goto(0, 0)  # spawns in


# fucntions
def go_up():
    y = Block.ycor()
    Block.sety(y + 20)


def go_down():
    y = Block.ycor()
    Block.sety(y - 20)


def go_left():
    x = Block.xcor()
    Block.setx(x - 20)


def go_right():
    x = Block.xcor()
    Block.setx(x + 20)


# keyboard
Screen.onkey(go_up, "w")
Screen.onkey(go_down, "s")
Screen.onkey(go_left, "a")
Screen.onkey(go_right, "d")
Screen.listen()

Screen.mainloop()
Reply


Messages In This Thread
RE: [Turtle]Need help with moving a square on key press - by Yoriz - May-18-2019, 05:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle / turtle question DPaul 2 2,131 Oct-04-2020, 09:23 AM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020