title: Python Calculator in Tkinter - Functions auto-running
body: <p>I am making a graphical calculator in Python 2.7.3 with Tkinter. I have set it up so when the user pushes the 'b' button it will print 'b' to the console. I do this by making a function that is passed a variable called 'key' which it then adds to the label. However, when I first start the program, it automatically calls the function and prints 'b' to the console. Whenever I click the button, it does nothing. Here is my code:</p>
  
  <pre><code>from Tkinter import *
  
  class Application(Frame):
      def addkey(self,key):
          print str(key)
  
      def removekey(self):
          if len(self.displaytext) &gt; 0:
              self.displaytext = self.displaytext[0:-1]
  
      def createWidgets(self):
          self.maxlength = 20
          self.displaytext = ""
  
          self.frame1 = Frame(self)
          self.display = Label(self.frame1,textvariable=self.displaytext,width=self.maxlength+3,bg="black",fg="white",height=2)
          self.frame1.pack()
          self.display.pack()
  
          self.frame2 = Frame(self)
          self.bksp = Button(self.frame2,text="b",width=4,height=2,command=self.addkey("b"))
          self.frame2.pack()
          self.bksp.pack()
  
  
      def __init__(self, master=None):
          Frame.__init__(self, master)
          self.pack()
          self.createWidgets()
  
  app = Application()
  app.mainloop()
  
  try:
      root.destroy()
  except:
      pass
  </code></pre>