Snake head now showing when trying to build the snake game using python module turtle

0 votes

I am trying to build the snake game using the python's turtle module. This is my code so far:

import turtle

#set up the screen
wn = turtle.Screen()
wn.title("snake game")
wn.bgcolor("Blue")
wn.setup(width=600, height=600)
wn.tracer(0)

#Snake Head
head = turtle.Turtle()
head.speed(0)
head.shape("square")
head.color("Black")
head.penup()
head.goto(0, 0)
head.direction = "stop"

turtle.mainloop()

I've created the snake head but when I test for it, it does not show. Is my logic wrong?

Jun 19, 2019 in Python by Nagya
340 views

1 answer to this question.

0 votes

Hey @Nagya, so you added the following line in your code:

wn.tracer(0)

It basically turns off the screen updates. Add the following lines:

# Main game loop
while True:
    wn.update()
answered Jun 19, 2019 by Faiza
I tried this, and I still have a blank screen with no paddle. I'm consistenly having this problem no matter which info I read about it. I'm running python 3.8.x Linux Mint 19.x.

Hello,

try turtle.getscreen() instead of turtle.Screen() at the beginning

Related Questions In Python

0 votes
0 answers
0 votes
1 answer

Change the snake head color using python turtle

You can et the snakehead color by ...READ MORE

answered Jun 19, 2019 in Python by Faiza
134 views
0 votes
1 answer

Draw a square using the turtle module - Python

Hey @Baily, use something like this: import turtle sq ...READ MORE

answered Jun 21, 2019 in Python by Himanshu
398 views
0 votes
1 answer

How do I create a star using the turtle module of python?

Hey @Jinu, Try something like this: import turtle star = ...READ MORE

answered Jun 21, 2019 in Python by Neha
319 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,466 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,095 views
0 votes
1 answer

Snake head placed on the center - Python using turtle

You can use turtle's goto() function. This ...READ MORE

answered Jun 21, 2019 in Python by Greg
129 views
0 votes
1 answer

Move turtle using the arrow keys in Python

You can use something like this: wn.onkey(move_up, 'Up') wn.onkey(move_left, ...READ MORE

answered Jul 5, 2019 in Python by Travis
1,191 views