title: How to create a counter for the number of times a button that was created was pressed in tkinter?
body: <p>So I have made a simple program that allows me to type a label for a button and have it created and clickable in the tkinter gui. Now all I need is to add a function that returns the number of times each individual button is clicked. The problem is that the buttons I created are not actually coded in the input so I've found it difficult to do this. I feel like I would have to use the lambda function but I have no experience at all with it. Help is appreciated, thank you.</p>
  <p>Code:</p>
  <pre><code>import tkinter as tk
  from tkinter import *
  
  window = tk.Tk()
  window.title(&quot;Tkinter FINAL&quot;)
  window.geometry(&quot;600x400&quot;)
  window.resizable(width=False, height=False)
  WIDTH = 800
  HEIGHT = 600
  
  counter_name = tk.Label(window, text=&quot;Counter Word&quot;, width=20)
  counter_name.place(x=460,y=318)
  counter_entry = tk.Entry(window, width=20)
  counter_entry.place(x=470,y=338)
  
  position_x = 0
  position_y = 0
  
  
  word_dict = {}
  def button_function():
      word_dict[title] += 1
  
  button_count = 0
  def button_maker():
      global position_x, position_y, button_count, title
      button = tk.Button(window, text=counter_entry.get(), width=10, height=2, command = button_function, fg=&quot;red&quot;)
      button.place(x=position_x,y=position_y)
      position_x += 116
      button_count += 1
      if button_count % 6 == 0:
          position_y += 50
          position_x = 0
      title = counter_entry.get()
      word_dict[title] = 0
      counter_entry.delete(0,'end')
  
  
  
  
  btnmaker = tk.Button(window, text='Click to create counter', width=17, height=2, command = button_maker, fg=&quot;red&quot;)
  btnmaker.place(x=470,y=358)
  
  
  
  btnreset = tk.Button(window, text='RESET', width=10, height=2, command = window.destroy, fg=&quot;red&quot;)
  btnreset.place(x=520,y=500)
  
  window.mainloop()
  </code></pre>