Python Tkinter索引器错误:列表超出范围
我正在制作一个膳食计划应用程序,它允许你设置你的配料和食谱,并根据它给你一个食品清单。 但是,当我运行它时,会出现以下错误:Python Tkinter索引器错误:列表超出范围,python,arrays,tkinter,Python,Arrays,Tkinter,我正在制作一个膳食计划应用程序,它允许你设置你的配料和食谱,并根据它给你一个食品清单。 但是,当我运行它时,会出现以下错误: 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/s
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"
我已经看了这个问题,但它没有回答我的问题:
这是我的密码:
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)
使用
ln=len(配方)
,recipe\u creator=tkinter.Button(text=“”,command=lambda:mkcomponent(ln))
,和recipeIncident.grid(row=len(配方[row-1])+1,column=row)
。问题是您正在创建按钮时运行该函数 使用ln=len(配方)
,recipe\u creator=tkinter.Button(text=“”,command=lambda:mkcomponent(ln))
,和recipeCredit.grid(row=len(配方[row-1])+1,column=row)
。问题是您正在创建按钮时运行该函数 你能公布整个错误吗?我想你已经把有用的信息删掉了。我试试看。一些技术问题使我无法复制和粘贴。你能发布整个错误吗?我想你已经把有用的信息删掉了。我试试看。一些技术问题使我无法复制和粘贴