Python NameError:未定义全局名称“enterFilePath”

Python NameError:未定义全局名称“enterFilePath”,python,tkinter,Python,Tkinter,我正在尝试使用python制作GUI。我正在使用Tkinter库和python 2.7 我的目标是获得我浏览到的路径,并将其作为字符串插入到输入框中,但不知何故,我无法做到这一点,我得到了上面标题中提到的错误 下面是我的代码片段: def browseSWPath(self): #global enterFilePath self.frameTwo = Frame(self.mainFrame, width=640, height=100, bg='white') sel

我正在尝试使用python制作GUI。我正在使用Tkinter库和python 2.7

我的目标是获得我浏览到的路径,并将其作为字符串插入到输入框中,但不知何故,我无法做到这一点,我得到了上面标题中提到的错误

下面是我的代码片段:

def browseSWPath(self):
    #global enterFilePath
    self.frameTwo = Frame(self.mainFrame, width=640, height=100, bg='white')
    self.frameTwo.pack(side='top', expand=False, fill='both')

    self.swFlashPath = Button(self.frameTwo, text='SW Flash Path', command=flashFile)
    self.swFlashPath.pack(side='left', padx=5, pady=5, anchor='nw')
    #self.swPath = StringVar()
    self.enterFilePath = Entry(self.frameTwo, bd=2, width=75)
    self.enterFilePath.pack(side='left', pady=10, anchor='nw')

def flashFile(): 
    pathName = tkFileDialog.askopenfilename()
    if pathName:
        enterFilePath.delete(0, END)
        enterFilePath.insert(0, str(pathName))
回溯:

正如@bryanOakley在上面的评论中所说,self.xx和xx不是一回事。对于那些正在寻找这个问题答案的人来说,有两个变化使它起了作用

正在从self.enterFilePath中删除self 在enterFilePath.delete0,Tkinter.END行中
非常感谢

请显示实际的完整错误。这是什么enterFilePath?似乎。。未定义。enterFilePath是类的一部分。我们不知道是哪一个。所以您需要class_instance_name.enterFilePath来使用它。假设flashFile不是该类的一部分,因为它没有自参数。粘贴enterFilePath图像时出现的错误未定义,问题路径名中的错误未定义。这两种情况不同。哪一个是真正的问题?您知道enterFilePath和self.enterFilePath不是一回事吗?