Python 名称错误:名称';选择设备';没有定义

Python 名称错误:名称';选择设备';没有定义,python,Python,我一直在尝试解决nameerror,但它不起作用。我试图编辑函数代码,但仍然是相同的错误。有没有办法解决这个问题 window = tk.Tk() tree = ttk.Treeview() columns = list(df.columns) combo = ttk.Combobox(values=list(df3["MFG Device"].unique()),state="readonly") combo.pack() combo.bind(&quo

我一直在尝试解决nameerror,但它不起作用。我试图编辑函数代码,但仍然是相同的错误。有没有办法解决这个问题

window = tk.Tk()
tree = ttk.Treeview()
columns = list(df.columns)
combo = ttk.Combobox(values=list(df3["MFG Device"].unique()),state="readonly")
combo.pack()
combo.bind("<<ComboboxSelected>>", select_device)
tree["columns"] = columns
tree.pack(expand=TRUE, fill=BOTH)

        #for i in columns:
            #self.tree.column(i, anchor="w")
            #self.tree.heading(i, text=i, anchor="w")

for index, row in df3.iterrows():
        tree.insert("", "end", text=index, values=list(row))

def select_device(event):
        #tree.delete(*self.tree.get_children())
        for index, row in df3.loc[df3["MFG Device"].eq(combo.get())].iterrows():
            tree.insert("", "end", text=index, values=list(row))

root = Application()
root.mainloop()
window=tk.tk()
tree=ttk.Treeview()
columns=列表(df.columns)
combo=ttk.Combobox(值=列表(df3[“制造设备”].unique()),state=“只读”)
combo.pack()
绑定(“,选择\设备)
树[“列”]=列
tree.pack(expand=TRUE,fill=BOTH)
#对于列中的i:
#self.tree.column(i,anchor=“w”)
#self.tree.heading(i,text=i,anchor=“w”)
对于索引,df3.iterrows()中的行:
插入(“,”结束“,文本=索引,值=列表(行))
def选择_设备(事件):
#tree.delete(*self.tree.get_children())
对于索引,df3.loc[df3[“制造设备”].eq(combo.get())].iterrows()中的行:
插入(“,”结束“,文本=索引,值=列表(行))
root=应用程序()
root.mainloop()
外壳:

Traceback (most recent call last):
  File "C:\Users\sgtiocqn\Desktop\123.py", line 21, in <module>
    combo.bind("<<ComboboxSelected>>", select_device)
NameError: name 'select_device' is not defined
回溯(最近一次呼叫最后一次):
文件“C:\Users\sgtiocqn\Desktop\123.py”,第21行,在
绑定(“,选择\设备)
名称错误:未定义名称“选择设备”

将函数移到“window=tk.tk()”行上方(非常感谢!)将函数移到“window=tk.tk()”行上方(非常感谢!)