0

I am making a meal planning application that allows you to set ingredients you have and recipes and gives you a grocery list based on it. When I run it, however, I get these errors:

IndexError: list index out of range 
Exception in Tkinter callback
...
Line 15: recipes[row-1].append(recipeIngredient): IndexError: list index out of range
File "/Users/*****/Documents/shopping planner.py"

I have looked at this question, but it doesn't answer my question: Python - IndexError: list index out of range
Here's my code:

def MkRecipe():
    recipe_creator = tkinter.Button(window, text=" ", command=MkIngredient(len(recipes)))
    recipe_creator.grid(row=1, column=(len(recipes)+1))
    recipes.append([])
def mkIngredient(row):
    recipeIngredient = tkinter.Entry()
    recipes[row-1].append(recipeIngredient)
    recipeIngredient.grid(row=len(recipes[row]), column=row)


2
  • Can you post the entire error? I think you've cropped out the useful info. Commented May 7, 2020 at 13:13
  • I'll try. Some technology problems are preventing me from copying and pasting Commented May 7, 2020 at 13:15

1 Answer 1

2

Use ln = len(recipe),recipe_creator = tkinter.Button(text=" ", command=lambda: MkIngredient(ln)), and recipeIngredient.grid(row=len(recipes[row-1])+1, column=row). The problem is that you are running the function on button creation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.