What you need is what is known as Game Loop.
Your code is working perfectly, but you application is exiting after the first render. So, to keep it rendering frames you need to keep your application alive, running. To do so you can do something like this:
import turtle
#set up the screen
app = turtle.Screen()
app.title("Your app")
app.bgcolor("black")
app.setup(width=1000, height=1000)
app.tracer(0)
ball = turtle.Turtle()
ball.color("orange")
ball.shape("circle")
ball.shapesize(1.2)
ball.speed(3)
ball.penup()
player1 = turtle.Turtle()
player1.color("blue")
player1.shape("arrow")
player1.shapesize(5)
player1.speed(3)
player1.penup()
player1.setpos(350,0)
player2 = turtle.Turtle()
player2.color("cyan")
player2.shape("arrow")
player2.shapesize(5)
player2.speed(3)
player2.penup()
player2.setheading(180)
player2.setpos(-350,0)
player1y = 0
player2y = 0
def player1up():
global player1y
player1y += 12
player1.goto(350,player1y)
def player1down():
global player1y
player1y -= 12
player1.goto(350,player1y)
def player2up():
global player2y
player2y += 12
player2.goto(-350,player2y)
def player2down():
global player2y
player2y -= 12
player2.goto(-350,player2y)
turtle.listen()
turtle.onkeypress(player1up, 'Up')
turtle.onkeypress(player1down, 'Down')
turtle.onkeypress(player2up, 'w')
turtle.onkeypress(player2down, 's')
while True:
app.update()
Basically, get the instance of the Screen, and call the update() method inside a while True loop, which will maintain your app running.
And all the code you have written is working as you expected.
Here is a little tutorial of another game made with the Turtle package. I believe it's not what you want to do but it could help as a guide.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…