Tastenkombinationen bewegen
da ist mein Code
Schildkröte importieren
Code: Select all
# inishialize screen
the_ping_pong_windows = turtle.Screen()
# set the screen title
the_ping_pong_windows.title("stage of ping pong")
# set the screen color
the_ping_pong_windows.bgcolor("black")
# set the widht and heigt of the window
the_ping_pong_windows.setup(width=1000, height=600)
# stops the window from updating automatically
the_ping_pong_windows.tracer(0)
# madrab 1
# create a turtle object (SHAPE) eli men 5laloh a2dar a3ml shakl el madrab eli ana 3ayzoh
madrab1 = turtle.Turtle()
# set the speed of the animation dih mi4 el sor3ah eli el mAdrab dih el sor3ah eli beyrsem biha el turtle object
# el madrab kol ma ytharak 34an a2dar a4ofoh
madrab1.speed(0)
madrab1.shape("square")
# set the madrab's color
madrab1.color("red")
madrab1.shapesize(stretch_wid=5, stretch_len=1)
madrab1.penup()
madrab1.goto(-420, 0)
# madrab 2
madrab2 = turtle.Turtle()
madrab2.speed(0)
madrab2.shape("square")
madrab2.color("blue")
madrab2.shapesize(stretch_wid=5, stretch_len=1)
madrab2.penup()
madrab2.goto(420, 0)
# ball
ball = turtle.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("white")
ball.penup()
ball.goto(0, 0)
# functions
def madrab1_up():
y = madrab1.ycor()
y += 20
madrab1.sety(y)
def madrab1_down():
y = madrab1.ycor()
y -= 20
madrab1.sety(y)
def madrab2_up():
y = madrab2.ycor()
y += 22
madrab2.sety(y)
def madrab2_down():
y = madrab2.ycor()
y -= 20
madrab1.sety(y)
# keyboard binding
the_ping_pong_windows.listen()
the_ping_pong_windows.onkeypress(madrab1_up,"w")
the_ping_pong_windows.onkeypress(madrab1_down,"g")
the_ping_pong_windows.onkeypress(madrab2_up,"s")
the_ping_pong_windows.onkeypress(madrab1_down,"Up")
the_ping_pong_windows.update()
the_ping_pong_windows.exitonclick()
Wenn ich zum Beispiel auf „w“ klicke, bewegt sich die Form nicht
und ich erhalte keine Fehlermeldung
Wenn jemand eine Möglichkeit hat, dieses Problem zu lösen, teilen Sie mir dies bitte mit
Vielen Dank im Voraus
Mobile version