A simple GUI-based Traffic Light Simulation built using Python and Tkinter. This project visually represents real-world traffic signals with a countdown timer for each light (Green, Yellow, Red).
- 🚦 Realistic Traffic Light Simulation
- ⏳ Countdown Timer for each signal
- 🖼️ Image-based light display (Green, Yellow, Red)
- 🔄 Continuous automatic cycling
- 🧠 Event-driven programming using Tkinter (
after())
- Python
- Tkinter (for GUI)
- Pillow (PIL) (for image handling)
https://github.com/ashishkumardata/Traffic-Light-using-Python-While-Loop-.gitpip install pillowpython main.pyMake sure these image files are present in the same directory:
green.pngyellow.pngred.png
-
The program cycles through traffic light states:
- 🟢 Green (15 seconds)
- 🟡 Yellow (5 seconds)
- 🔴 Red (15 seconds)
- 🟡 Yellow (5 seconds)
-
Uses Tkinter’s
after()method for smooth, non-blocking updates. -
Updates GUI every second with a countdown timer.
- 🎨 Replace images with animated shapes (Canvas)
- ⏯️ Add Start/Stop buttons
- 🚶 Add pedestrian crossing signal
- 📊 Integrate traffic density logic (AI/ML extension)
Contributions are welcome! Feel free to fork the repo and submit a pull request.
This project is open-source and available under the MIT License.
Ashish Kumar
⭐ If you like this project, don't forget to star the repository!


