Tkinter TypeError: setvar() takes exactly 1 argument (2 given)
<p>I am writing a GUI program with Tkinter. Everything runs smoothly except for the key bindings. When I test themI get</p>

<blockquote>
  <p>"TypeError: setvar() takes exactly 1 argument (2 given)"</p>
</blockquote>

<p>The problem is that I am passing no arguments in these instances so I don't understand where the issue lies. I jury rigged it by adding an extra argument to the function in question. This makes the binding work, but causes the buttons that share the command to kick back the inverse type error</p>

<blockquote>
  <p>"TypeError: setvar() takes exactly 2 arguments (1 given)"</p>
</blockquote>

<p>The code is below. </p>

<p>The bindings in question are in lines: 18, 27, 186, 187, 212, 230.</p>

<p>They call the methods: manipulate.setvar(), manipulate.searching(), manipulate.stuff() and manipulate.newent()</p>

<pre><code>#!/usr/bin/python2.7

from Tkinter import *
import ttk
import os
import json

global inventory
global where
where = False
class widgets:

    def partnumber(self, parent, mode):
            global PN
            do = manipulate()
            PN_in = ttk.Entry(parent, width=11, textvariable=PN)
            if mode == 1:
                PN_in.bind('&lt;1&gt;', do.setvar)
            PN_in.grid(column=1, row=1, sticky=(W, E, S))
            ttk.Label(parent, text='Part#').grid(column=1, row=2, sticky=(N, W))

    def description(self, parent, mode):
            global DESC
            do = manipulate()
            DESC_in = ttk.Entry(parent, width=20, textvariable=DESC)
            if mode == 1:
                DESC_in.bind('&lt;1&gt;', do.setvar)
            DESC_in.grid(column=2, row=1, sticky=(E, S))
            ttk.Label(parent, text='Description').grid(column=2, row=2, sticky=(N, W))

    def quantity(self, parent):
            global QTY
            QTY_in = ttk.Entry(parent, width=3, textvariable=QTY)
            QTY_in.grid(column=3, row=1, sticky=(S))
            ttk.Label(parent, text='Qty.').grid(column=3, row=2, sticky=(N))

    def cost(self, parent):
            global COST
            COST_in = ttk.Entry(parent, width=6, textvariable=COST)
            COST_in.grid(column=4, row=1, sticky=(S))
            ttk.Label(parent, text='Cost').grid(column=4, row=2, sticky=(N))

    def quanchangebox(self, parent):
        global MANQUAN
        MANQUAN_in = Spinbox(parent, from_=1, to=10, textvariable=MANQUAN)
        MANQUAN_in.pack()

class manipulate:

    global name
    name = str('BNEIDATA.txt')

    def searching(self):
        do = manipulate()
        do.search(0)

    def changevar(self, PN):
        item = inventory[PN.get()]
        DESC.set(item[0])
        QTY.set(item[1])
        COST.set(item[2])

    def getresults(self):
        global result, RESULT, inventory, PN, DESC, QTY, COST
        hit = inventory[PN.get()]
    do = manipulate()
    do.changevar(PN)
        bit = str(PN.get())
        result.insert(0, bit)
        bit = str(hit[0])
        RESULT.insert(0, bit)
        result.activate(1)

    def search(self, mode):
        global inventory, PN, DESC
        do = manipulate()
        do.load()
        popup = boxes()
        if inventory.get(PN.get(), False) != False:
            do.getresults()
            if mode == 1:
                popup.howmany(mode)
            if mode == 2:
                popup.howmany(mode)
        if inventory.get(PN.get(), False) == False:
            ghostdict = {}
            for key in iter(inventory):
                entry = inventory[key]
                ghostdict[entry[0].encode()] = key
            if ghostdict.get(DESC.get(), False) != False:
                PN.set(ghostdict[DESC.get()])
                do.search(mode)
            if ghostdict.get(DESC.get(), False) == False:
                popup = boxes()
                popup.additem()

    def newent(self):
        do = manipulate()
        global addbox, PN, DESC, QTY, COST
        temp = [DESC.get(), QTY.get(), COST.get()]
            inventory[PN.get()] = temp
        do.writ()
        addbox.destroy()

    def writ(self):
            global inventory
            os.remove(name)
            with open(name, 'a') as datafile:
                    datafile.write(json.dumps(inventory))
            reset = manipulate()
            reset.setvar()

    def create(self):
            with open(name, 'a') as datafile:
                    bogusfirstentry = {'049007042':['Nylon Bushing', '75', '.47']}
                    datafile.write(json.dumps(bogusfirstentry))

    def find(self, name, breed, path):
            global where
            if breed == 1:
                    for root, dirs, files in os.walk(path):
                            if name in files:
                                    where = root
            if breed == 2:
                    for root, dirs, files in os.walk(path):
                            if name in dirs:
                                    where = os.path.join(root, name)

    def load(self):
            with open(name, 'r') as datafile:
                    temp = datafile.read()
                    global inventory
                    inventory = json.loads(temp)
                    ghostdict = {}
                    for key in iter(inventory):
                        entry=inventory[key]
                        ghostdict[key] = [entry[0].encode(), entry[1], entry[2]]
                    inventory = ghostdict

    def setvar(self):
            global PN, DESC, QTY, COST
            PN.set('')
            DESC.set('')
            QTY.set(0)
            COST.set(0)

    def recieve(self):
        do = manipulate()
        do.search(1)

    def use(self):
        do = manipulate()
        do.search(2)

    def quan_up(self):
        global MANQUAN, PN, inventory, quanbox
        do = manipulate()
        quan = inventory[PN.get()]
            temp = [quan[0], (quan[1]+MANQUAN.get()), quan[2]]
            inventory[PN.get()] = temp
            do.writ()
            quanbox.destroy()
            do.setvar()

    def quan_dn(self):
        global MANQUAN, PN, inventory, quanbox
        do = manipulate()
        quan = inventory[PN.get()]
            temp = [quan[0], (quan[1]-MANQUAN.get()), quan[2]]
            inventory[PN.get()] = temp
            do.writ()
            quanbox.destroy()
            do.setvar()

    def stuff(self):
        global result, RESULT, PN
        do = manipulate()
        PN.set(result.get(result.curselection()[0]))
        do.changevar(PN)

class boxes:
    def main(self):
        do = manipulate()
            root = Tk()
            root.title('BNE Inventory Database')
            root.bind('&lt;Return&gt;', do.searching)
            root.bind('&lt;BackSpace&gt;', do.setvar)
            mainframe = ttk.Frame(root, padding='3 3 3 3')
            mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
            mainframe.columnconfigure(0, weight=1)
            mainframe.rowconfigure(0, weight=1)
            global result, RESULT, PN, DESC, QTY, COST
            PN, DESC, QTY, COST = StringVar(), StringVar(), IntVar(), DoubleVar()

            field = widgets()
            field.partnumber(mainframe, 1)
            field.description(mainframe, 1)
            field.quantity(mainframe)
            field.cost(mainframe)

            ttk.Button(mainframe, text='Search', command=do.searching).grid(column=3, row=6, sticky=(W, E, N))
        ttk.Button(mainframe, text='Recieved', command=do.recieve).grid(column=3, row=6, sticky=(W, E, S))
            ttk.Button(mainframe, text='Adj Cost', command=root.destroy).grid(column=4, row=6, sticky=(W, E, N))
            ttk.Button(mainframe, text='Used', command=do.use).grid(column=3, row=6, sticky=(W, E))
            ttk.Button(mainframe, text='Clear Fields', command=do.setvar).grid(column=4, row=6, sticky=(W, E, S))
            ttk.Button(mainframe, text='Reports', command=root.destroy).grid(column=4, row=6, sticky=(W, E))

            RESULT = Listbox(mainframe, height=5)
            RESULT.grid(column=2, row=6, sticky=(W, E, S))
            result = Listbox(mainframe, height=5, width=11)
            result.grid(column=1, row=6, sticky=(W, E, S,))
            result.bind('&lt;&lt;ListboxSelect&gt;&gt;', do.stuff)

            root.mainloop()

    def additem(self):
            global PN, DESC, QTY, COST, addbox
            addbox = Toplevel()
            addbox.title('Add New Item')
            addboxframe = ttk.Frame(addbox, padding='3 3 3 3')
            addboxframe.grid(column=0, row=0, sticky=(N, W, E, S))
            addboxframe.columnconfigure(0, weight=1)
            addboxframe.rowconfigure(0, weight=1)
            field = widgets()
            field.partnumber(addboxframe, 0)
            field.description(addboxframe, 0)
            field.quantity(addboxframe)
            field.cost(addboxframe)
            do = manipulate()
            addbox.bind('&lt;Return&gt;', do.newent)
            ttk.Button(addboxframe, text='Add New Item', command=do.newent).grid(columnspan=5, row=3, sticky=(W, E))

    def howmany(self, mode):
        global MANQUAN, quanbox
        field = widgets()
        do = manipulate()
        MANQUAN = IntVar()
        quanbox = Toplevel()
        quanboxframe = ttk.Frame(quanbox, padding='3 3 3 3')
        quanboxframe.grid(column=0, row=0, sticky=(N, W, E, S))
        quanboxframe.columnconfigure(0, weight=1)
            quanboxframe.rowconfigure(0, weight=1)
            field.quanchangebox(quanboxframe)
            if mode == 1:
                quanbox.title('Item(s) Recieved')
                ttk.Button(quanboxframe, text=' + Parts', command=do.quan_up).pack()
        if mode == 2:
                quanbox.title('Item(s) Used')
                ttk.Button(quanboxframe, text=' - Parts', command=do.quan_dn).pack()

if __name__ == '__main__':
    check = manipulate()
    gui = boxes()
    check.find('BNEIDATA.txt', 1, '/')
    if where == False:
            check.create()
            check.load()
    if where != False:
            check.load()
    gui.main()
</code></pre>

<p>When you bind an event to an object-oriented handler:</p>

<pre><code>PN_in.bind('&lt;1&gt;', do.setvar)
</code></pre>

<p>it will call the handler with two arguments <code>(self, event)</code></p>

<p>But you've only defined the hander to take one:</p>

<pre><code>def setvar(self):
</code></pre>

<p>If you don't need the information contained in the <code>event</code> argument, you could possibly just define it as an argument with a default value but not use it:</p>

<pre><code>def setvar(self, event=None):
</code></pre>

<p>By defaulting the value to <code>None</code>, you should still be able to call it as a method with no arguments (implied <code>self</code> argument) in your code:</p>

<pre><code>do.setvar()
</code></pre>

<p>An alternate way to do this is split it into two methods, a two argument one, for binding, that simply calls the one argument version that everthing else uses.</p>

python tkinter