title: Getting button names from loop in python
body: <p>I am trying to create restaurant management system that I designed the foods and other services to represent in buttons so one ever button to save the button's name and the number of clicks in the textbox(receipt). It would look like this:
  <a href="https://i.stack.imgur.com/hJWxY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hJWxY.png" alt="enter image description here"></a></p>
  
  <p>My problem is how to get the button text generated by a for loop and inset into textbox</p>
  
  <p>This is part of my code:</p>
  
  <pre><code>def readbreakfast():  #this reads food names from database
      cur.execute("SELECT name FROM breakfast")
      return cur.fetchall()
  
  def showbreakfast(): #this reads names into buttons
      global name
      data1 = readbreakfast()
      for index, dat in enumerate(data1):
         name= ttk.Button(master, text=dat[0],command=lambda row=index+1:update_count(row))
         name.grid(row=index+1, column=0,padx=0, pady=0)
  def update_count(value):   #this gets button name and number of clicks 
      global bttn,bttn_clicks,my_text
      my_text=StringVar()
      my_text = dat.cget('text')
      bttn_clicks += 1
      bttn = IntVar()
      global variable
      variable = value
      print(update_count)
  
  
  def Receipt():   #text of the button that is clicked is to insert here
      txtReceipt.delete("1.0", END)
      x = random.randint(10908, 500876)
      randomRef = str(x)
      Receipt_Ref.set("BILL" + randomRef)
  
      txtReceipt.insert(END, 'Receipt Ref: \t\t\t'+Receipt_Ref.get()+"\t\t"+DateofOrder.get()+"\n")
      txtReceipt.insert(END, 'Items\t\t'+'Quantity\t\t\t'+"Price \n\n")
  
      if variable == 1:
          txtReceipt.insert(END, str(my_text)+'\t\t'+str(bttn_clicks)+'\t\t\t'+""+str(bttn_clicks*3)+"\n")
       if variable == 2:
          txtReceipt.insert(END, str(my_text)+'\t\t'+str(bttn_clicks)+'\t\t\t'+""+str(bttn_clicks*3)+"\n")
  
          I have found different code examples but nothing specific enough to implement into my program. Any advice is much appreciated!
  </code></pre>