Skip to content

Commit

Permalink
Added recipe finder
Browse files Browse the repository at this point in the history
  • Loading branch information
purnima2904 committed Oct 28, 2024
1 parent a677197 commit c6b926c
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Beginner_Projects/Recipe_Finder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Recipe Finder Using Tkinter

## Overview

This project is a simple **Recipe Finder** built using **Tkinter**, a GUI library in Python. The application allows users to input ingredients they have at home and find suitable recipes. It uses the Spoonacular API to fetch and display recipes based on the provided ingredients.

## Features

- **Graphical User Interface (GUI):** The interface allows users to easily input ingredients and view corresponding recipe suggestions.
- **Recipe Search:** Users can enter a list of ingredients, and the application retrieves recipes that can be made with those ingredients.
- **Clickable Recipe Links:** The application provides links to actual recipes on the Spoonacular website, allowing users to view detailed instructions and ingredients.

## How It Works

1. **Spoonacular API:**
- The application utilizes the Spoonacular API to access a large database of recipes. The API requires an API key for access, which must be included in the code.

2. **Tkinter GUI:**
- The GUI is built using `Tkinter`, featuring an input field for entering ingredients and a button to initiate the recipe search.
- Upon clicking the "Find Recipes" button, the application sends a request to the Spoonacular API with the specified ingredients.

3. **Displaying Recipes:**
- The results are displayed in a new window, showing the titles of the recipes. Each recipe title is a clickable link that opens the corresponding recipe in a web browser.

## How to Run the Project

1. Clone the repository or download the project files.
2. Ensure you have Python 3.x installed on your machine.
3. Install the required libraries using pip:
```bash
pip install requests
```
4. Replace the placeholder API key in the script with your Spoonacular API key.
5. Run the `recipe_finder.py` script using Python:
```bash
python recipe_finder.py
```
6. Enter ingredients separated by commas in the input box and click "Find Recipes." The application will display recipe suggestions.

## Requirements

- Python 3.x
- Tkinter library (included with Python)
- `requests` library (install via pip)

## Future Enhancements

- **Save Favorite Recipes:** Allow users to save their favorite recipes for quick access.
- **Ingredient Suggestions:** Provide suggestions for recipes based on partial ingredients or commonly available items.
- **User Accounts:** Implement user accounts to save preferences and custom ingredient lists.
60 changes: 60 additions & 0 deletions Beginner_Projects/Recipe_Finder/recipe_finder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import requests
import tkinter as tk
from tkinter import messagebox
import webbrowser

def find_recipes(ingredients):
SPOONACULAR_API_KEY = 'feb01116afe3415cb6cca75636a799d8'
url = f'https://api.spoonacular.com/recipes/findByIngredients?ingredients={ingredients}&apiKey={SPOONACULAR_API_KEY}'

response = requests.get(url)

if response.status_code == 200:
return response.json()
else:
messagebox.showerror("Error", "Failed to retrieve recipes.")
return []

def open_recipe(url):
webbrowser.open(url)

def display_recipes(recipes):
# Create a popup window with a specified size
recipe_window = tk.Toplevel()
recipe_window.title("Recipe Results")
recipe_window.geometry("500x400") # Set the size of the popup window (width x height)

for recipe in recipes:
recipe_name = recipe['title']
recipe_url = f"https://spoonacular.com/recipes/{recipe['id']}-{recipe_name.replace(' ', '-')}"

recipe_link = tk.Label(recipe_window, text=recipe_name, fg="blue", cursor="hand2")
recipe_link.pack(pady=10)

# Bind click event to open the recipe URL
recipe_link.bind("<Button-1>", lambda e, url=recipe_url: open_recipe(url))

def search_recipes():
ingredients = ingredients_entry.get() # Get ingredients from the entry field
if ingredients:
recipes = find_recipes(ingredients)
display_recipes(recipes)

# Create the main window
root = tk.Tk()
root.title("Recipe Finder")
root.geometry("500x300") # Increase the size of the main window

# Set a colorful background
root.configure(bg="#6A5ACD")

# Ingredients input
tk.Label(root, text="Enter ingredients (comma-separated):", bg="#ffffff", font=("Helvetica", 14)).pack(pady=10)
ingredients_entry = tk.Entry(root, width=40, font=("Helvetica", 14), bg="#FFE4B5") # Light lemon chiffon color
ingredients_entry.pack(pady=50)

# Search button
search_button = tk.Button(root, text="Find Recipes", command=search_recipes, bg="#90EE90", font=("Helvetica", 14)) # Light green color
search_button.pack(pady=20)

root.mainloop()

0 comments on commit c6b926c

Please sign in to comment.