Friday, FED, 6, 2026

Today This Free Friday I am working on a project on YouTube a Snake game.

from tkinter import *
import random

GAME_WIDTH = 700
GAME_HEIGHT = 700
SPEED = 50
SPACE_SIZE = 50
BOBY_PARTS = 3
SNAKE_COLOR = "#00FF00"
FOOD_COLOR = "#FF0000"
BACKGROUND_COLOR = "#000000"
  • This part of the code is for the screen width and height and to color the background and for the snake color and food for the snake game.
window = TK()
window.title("Snake game")
window.resizable(False, False)

score = 0
direction = "down"

label = label(window, text="Score:{}".format(score), font=('consolas', 40))

canvas = Canvas(window, bg=BACKGROUND_COLOR, height=GAME_HEIGHT, width= GAME_WIDTH)
canvas.pack()

window.update()

window_width = window.winfo_windth()
window_height = window.winfo_height()
screen_width = window.winfo_sreenwidth()
screen_height = window.winfo_screenheight()

x = int((screen_width/2) - (window_width/2))
y = int((screen_height/2) - (window_height/2))

window.geometry(f"{window_width}x{window_height}+{x}+{y}")

snake = Snake() 
food = Food()




window.mainloop()
  • This is the code for the window label score and the width and height for the canvas color background.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top