I am trying to create Snake game but tkinter window closes before i can see anything
i have used turtle.mainloop()
, but still no use
import turtle as t
import random as rd
import time as ti
wn = t.Screen()
wn.bgcolor('yellow')
wn.title('Snake game')
wn.canvheight(200)
wn.canvwidth(300)
snake = t.Turtle()
scores = t.Turtle()
text = t.Turtle()
leaf = t.Turtle()
def start():
pass
def down_move():
if snake.heading() == 0 or snake.heading() == 180:
snake.setheading(270)
def up_move():
if snake.heading() == 0 or snake.heading() == 180:
snake.setheading(90)
def left_move():
if snake.heading() == 90 or snake.heading() == 270:
snake.setheading(180)
def right_move():
if snake.heading() == 90 or snake.heading() == 270:
snake.setheading(0)
text.write("Start the game", align = "center", font=("Arial", 50, "bold"))
wn.onkey(start, "space")
wn.onkey(down_move,"Down")
wn.onkey(up_move,"Up")
wn.onkey(left_move,"Left")
wn.onkey(right_move,"Right")
wn.listen()
wn.mainloop()
I use Visual Studio Code as editor Please let me know how i can stop this And looks like, it not the code but something else