Setting Window Icon tkinter
<p>I'm trying to change the icon on my tkinter window and I think my problem is stemming from my lack of understanding classes.</p>

<p>I want to know why:</p>

<pre><code>import tkinter
root = tkinter.Tk()
img = tkinter.PhotoImage(file = r'stockIcon.gif')
root.tk.call('wm', 'iconphoto', root._w, img)

root.mainloop()
</code></pre>

<p>works perfectly. But:</p>

<pre><code>import tkinter

class Test:
    def __init__(self):
        self.root = tkinter.Tk()
        self.img = tkinter.PhotoImage(file = r'stockIcon.gif')
        self.root.tk.call('wm', 'iconphoto', root._w, img)
        self.root.mainloop()

test = Test()
</code></pre>

<p>throws <code>NameError: name 'root' is not defined</code>. What am I misunderstanding?</p>