title: How to pass a python event variable into another function?
body: <p>I am working on building a simple GUI and I am running into an issue when trying to pass in an event variable into another function that already has an event variable. </p>
  
  <p>I am trying to use the variable "sqlItemx", which is an event variable for "self.item1", into the function "addNumbs".  </p>
  
  <p>How can I pass this variable for later use? </p>
  
  <p>I have tried simply passing the variable in the usual convention but this did not work for me.</p>
  
  <p>An excerpt of my code is listed below: </p>
  
  <pre><code>def listitems(self, event):
      for widget in self.itemFrame.winfo_children():
          widget.destroy()
      searchLettersx = event.widget['text']
      mycursor.execute("SELECT Name FROM inventory WHERE Name LIKE '" + searchLettersx + "%' ")
      myresult = mycursor.fetchall()
      rcount = 0
      ccount = 0
      for y in myresult:
          self.item1 = tk.Button(self.itemFrame, text=y, bg='white', fg='deep sky blue', font=("Helvetica", 18), height='4', width='22')
          self.item1.grid(column=ccount, row=rcount)
          self.item1.bind('&lt;Button-1&gt;', self.addtoCart)
          if rcount &gt;= 5:
              ccount += 1
              rcount = 0
          rcount += 1  
  
   def addtoCart(self, event):
      win = tk.Toplevel(bg="white")
      win.wm_title("Add to Cart")
  
      sqlItemx = event.widget['text']
  
      frame = tk.Frame(win)
      frame.grid()
      self.numpadFrame = tk.Frame(win, pady='20', bg="white")
      self.numpadFrame.grid(column='0', row='2')
  
      itemLabel = tk.Label(win, text=sqlItemx, bg="white", font=("Helvetica", 18), pady="30")
      itemLabel.grid(row=0, column=0)
  
      numLabel = tk.Label(win, text="How many? ", bg="white", font=("Helvetica", 18), pady="30", anchor='e', justify='left')
      numLabel.grid(row=1, column=0)
  
      numbers = ["1", "2", "3", "4" , "5" , "6" , "7" , "8" , "9" , " " , "0" , " "]
      count = 0
  
      for r in range(4):
          for c in range(3):
              numpad = tk.Button(self.numpadFrame, text=numbers[count], height='4', width='8', bg='white', fg='deep sky blue', font=("Helvetica", 18))
              numpad.grid(row=r+1,column=c)
              numpad.bind('&lt;Button-1&gt;', self.addNumbs)
              count += 1
  
      finalize = tk.Button(win, text="Submit", height='2', width='14', bg='white', fg='deep sky blue', font=("Helvetica", 18))
      finalize.grid(column='0', row='7', columnspan='4')
      finalize["command"] = win.destroy
  
  def addNumbs(self, event):
  
      numPadx = event.widget['text']
  
      sql = "INSERT INTO tempcart (item, count) VALUES (%s, %s)"
      val = ("item", numPadx)
      addtempCart.execute(sql, val)
      mydb.commit()
  
      gettempCartID.execute("SELECT ID FROM tempcart ORDER BY ID DESC LIMIT 1")
      gettempCartID_result = gettempCartID.fetchall()
  
      gettempCart.execute("SELECT item, count FROM tempcart")
      gettempCart_result = gettempCart.fetchall()
  
      for y in gettempCart_result:
          for z in gettempCartID_result: 
              self.cartItem = tk.Label(self.cartFrame, text=y, bg="white", font=("Helvetica", 20))
              self.cartItem.grid(column="0", row=z)
  
      mydb.commit()
  </code></pre>
  
  <p>My end goal is to be able to able to pass the value of this variable into "addNumbs" and use it as one the values in variable "val" for my MySQL statement.</p>