Change the window background color using turtle - python

0 votes

I'm trying to build the snake game using turtle (python module). I've created the window and the snakehead so far. The background color of the window is white. I want it to be blue. How do I change it? Thank you 

Code:

import turtle

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

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


# Main game loop
while True:
    wn.update()

turtle.mainloop()

Jun 19, 2019 in Python by Mihir
16,001 views

1 answer to this question.

0 votes

Try this:

import turtle

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

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


# Main game loop
while True:
    wn.update()

turtle.mainloop()

Hope it works!!

If you are a beginner and need to know more about Python, It's recommended to go for Python Certification course today.

Thanks!

answered Jun 19, 2019 by Faiza

Related Questions In Python

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
1,684 views
0 votes
1 answer

How change title bar background color in python tkinter?

You cant change colour cause its the ...READ MORE

answered Jun 10, 2020 in Python by bezlin
8,491 views
0 votes
1 answer
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
576 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,007 views
0 votes
1 answer
+5 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,790 points
3,386 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 4, 2018 in Python by charlie_brown
• 7,720 points
12,858 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 22, 2019 in Python by Himanshu
1,265 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP