NameError: global name 'Path' is not defined
<p>I'm a beginner of learning GUI. My python version is 2.7,and I'm using windows</p>

<p>what should I do to be able to change the value of "path" by clicking button?</p>

<p>here is the part of my code.  :)</p>

<pre><code>class Sign_page(tk.Frame):
    def __init__(self, parent, controller):
        self.controller = controller
        tk.Frame.__init__(self, parent)

        img_path = "C:/"
        Path = tk.Text(self, width = 45, height=1)
        Path.insert("end",img_path)
        Path.grid(row=2,column=0)

        ask_path = tk.Button(self, text = "...", command = lambda: asking_path(self))
        ask_path.grid(row=2,column=1)
</code></pre>

<p>and this part is out of class "Sign_page"</p>

<pre><code>def asking_path(self):
    fileName = askopenfilename(initialdir = "C:/")
    img_path = fileName
    Path.delete("1.0","end")
    Path.insert("end",img_path)
</code></pre>

<p><code>Path</code> is not accessible from <code>asking_path</code> because it's not defined in the scope. One solution is to set an attribute on the instance when you create <code>Path</code> in <code>__init__</code>. In general, you should use lowercased variable names for Python variables ("<code>path</code>"), and title case for class names ("<code>SignPage</code>").</p>

<pre><code>class SignPage(tk.Frame):
    def __init__(self, parent, controller):
        ...
        path = tk.Text(self, width = 45, height=1)
        path.insert("end",img_path)
        path.grid(row=2,column=0)
        self.path = path
        ...

    def asking_path(self):
        ...
        self.path.delete("1.0","end")
        self.path.insert("end",img_path)
</code></pre>

python user-interface tkinter