Tkinter class module reference exception
<p>I'm having some trouble calling a module(updateUI) within a class (Eventsim).</p>

<p>The line Sim = EventSim() throws an exception because it's missing an argument (parent). I can't figure out how to fix this / reference the parent object.</p>

<p>This is my first attempt wit Tkinter and my python knowledge is also rather limited (for now).</p>

<pre><code>from Tkinter import *


class EventSim(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)

        self.parent = parent

    def updateUI(self,IP_Address,Port_Number,Events_Directory):

        self.parent.title('ECP Event Simulator')
        self.parent.resizable(0, 0)
        self.pack(fill=BOTH, expand=True)

        frame1 = Frame(self)
        frame1.pack(fill=X)
        frame2 = Frame(self)
        frame2.pack(fill=X)
        frame3 = Frame(self)
        frame3.pack(fill=X)
        frame4 = Frame(self)
        frame4.pack(fill=X)
        frame5 = Frame(self)
        frame5.pack(fill=X)
        frame6 = Frame(self)
        frame6.pack(fill=X,pady=(10,30))
        frame7 = Frame(self)
        frame7.pack(fill=X)
        frame8 = Frame(self)
        frame8.pack(fill=X,pady=(10,0))


        Main_Label = Label(frame1,text='ECP EventSim')
        Main_Label.pack(side=LEFT,padx=100)

        IP_Label = Label(frame2,text='IP Address:')
        IP_Label.pack(side=LEFT,padx=10)
        Port_Label = Label(frame2,text='Port:')
        Port_Label.pack(side=RIGHT,padx=70)

        IP_Text = Entry(frame3)
        IP_Text.pack(fill=X,side=LEFT,padx=10)
        IP_Text = Entry(frame3)
        IP_Text.pack(fill=X,side=RIGHT,padx=10)

        Dir_Label = Label(frame4,text='Events Directory:')
        Dir_Label.pack(side=LEFT,padx=10)
        Dir_Text = Entry(frame5)
        Dir_Text.pack(fill=X,side=LEFT,padx=10,expand=True)

        Save_Button = Button(frame6,text='Save Config')
        Save_Button.pack(fill=X,side=LEFT,padx=10,expand=True)
        Con_Button = Button(frame7,text='Connect')
        Con_Button.pack(fill=X,side=LEFT,padx=10,expand=True)
        Send_Button = Button(frame8,text='Start Sending Events')
        Send_Button.pack(fill=X,side=LEFT,padx=10,expand=True)

def main():
    root = Tk()
    root.geometry("300x300+750+300")
    app = EventSim(root)
    root.mainloop()


Sim = EventSim()
Sim.updateUI('1','1','1')
main()
</code></pre>

<p>The <code>parent</code> should be <code>root</code>. So, replacing:</p>

<pre><code>def main():
    root = Tk()
    root.geometry("300x300+750+300")
    app = EventSim(root)
    root.mainloop()


Sim = EventSim()
Sim.updateUI('1','1','1')
main()
</code></pre>

<p>with:</p>

<pre><code>root = Tk()
root.geometry("300x300+750+300")
Sim = EventSim(root)
Sim.updateUI('1','1','1')
root.mainloop()
</code></pre>

<p>brings up the desired window. The <code>updateUI</code> method requires work to populate the entry fields but you can remove its <code>parent</code> parameter since you already have the <code>parent</code> instance variable.</p>

python class tkinter