A classic Snake game with a graphical user interface, developed in Python using tkinter.
The project supports keyboard controls, a scoring system, win conditions, and game-over logic.
The game consists of:
- A controllable snake
- Randomly generated apples
- Score display
- Win and game-over screens
- Keyboard controls via arrow keys or WASD
- Python 3
- Tkinter (GUI)
- Random
- OS module
project/
│
├── snake.py
├── tetris.png
└── README.mdRequired:
- Python 3.10 or newer
Check with:
python --versiongit clone https://github.com/Mythryl-dev/Python_Snake_Game_in_Tkinter.git
cd Python_Snake_Game_in_Tkinterpython snake.py| Key | Function |
|---|---|
| ↑ / W | Move up |
| ↓ / S | Move down |
| ← / A | Move left |
| → / D | Move right |
| Q | Quit game |
| ESC | Quit game |
-
The snake continuously moves across the game field.
-
When collecting an apple:
- the snake grows,
- the score increases,
- a new apple appears randomly.
-
The game ends when:
- colliding with the wall,
- colliding with its own body.
-
The player wins at 30 points.
The game is currently optimized for:
- 2560×1440 with 225% scaling
Alternative values for 1920×1080 are already included in the code and can be enabled.
The following values can easily be changed in the code:
SPEED = 100
SPACE_SIZE = 100
BODY_PARTS = 3SNAKE_COLOUR = "#00FF00"
FOOD_COLOUR = "#FF0000"
BACKGROUND_COLOUR = "#000000"GAME_WIDTH = 1137 * 2
GAME_HEIGHT = 640 * 2SPEED = 100The higher the value, the slower the game runs.
SPACE_SIZE = 50 * 2- GUI with Tkinter
- Score system
- Random food generation
- Win condition
- Game-over screen
- Keyboard controls
- Centered game window
- Custom window icon
This project is especially suitable for learning:
- Object-oriented programming (OOP)
- GUI development with Tkinter
- Event handling
- Game logic
- Collision detection
- Working with classes and functions
- Sometimes an apple spawns inside the snake’s body