title: How Do I assign a function to a button in Python/TKinter?
body: <p>I am fairly new to TKinter and have been trying to convert my normal Python code into a GUI (TKinter Code)! I have been working on this code and so far, I have got the basic layout made but I am having problems coding buttons and using entries. You will most likely find a lot of errors in my code so be warned! :D</p>
  
  <p>I have got an entry at the top of the window and I want the user to input a number into the entry and then I want to use the text inputted in the entry in some code (<code>btn1()</code>). I also want the user to press a button and then the button to run some code with labels underneath where the buttons are showing the results of the code (the labels in the <code>btn1()</code> function).</p>
  
  <p>First, I want the user to input a number into the entry. Then, I want the user to click on a button which is underneath the entry. Finally, I want the results of the code behind the button, to be show underneath the buttons (in labels!).</p>
  
  <p>Here is my code:</p>
  
  <pre><code>from tkinter import *
  
  class window_design:
  
  def __init__(self):
      root=Tk()
      root.title("Bag Weight")
      root.geometry("500x700")
      root.wm_iconbitmap('favicon.ico')
  
  
      image=PhotoImage(file="Weight Program.png")
      imagelabel=Label(root,image=image)
      imagelabel.pack()
  
  
      weightentrylabel=Label(root,text="Enter Weight!")
      weightentrylabel.pack()
  
      self.string=StringVar()
      weightentry=Entry(root,textvariable=self.string)
      weightentry.pack()
  
      menutext=Label(root,text="What coin are you using?")
      menutext.pack(side=LEFT)
  
      values=['1p','2p','5p','10p','20p','50p','£1','£2','Exit']
  
      def btn1(self,btn1code):
          p1=3.56
          p1should=356
          if (self.string.get()) &gt; p1should:
              weightdif=(self.string.get())-p1should
              coins=weightdif/p1
              labeldif=Label(text=weightdif)
              labelcoins=Label(text=coins)
          elif (self.string.get()) &lt; p1should:
              weightdif=p1should-(self.string.get())
              coins=weightdif/p1
              labeldif=Label(text=weightdif)
              labelcoins=Label(text=coins)
  
      button1=Button(root,text="1p",command=btn1)
      button1.pack(side=LEFT)
  
  
  
      root.mainloop()
  
  
  
  window_design()
  </code></pre>
  
  <p>I am currently getting this error:</p>
  
  <pre><code>Exception in Tkinter callback
  Traceback (most recent call last):
    File "C:\Users\cjay2\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 1549, in __call__
      return self.func(*args)
  TypeError: btn1() missing 2 required positional arguments: 'self' and 'btn1code'
  </code></pre>