title: How to avoid repeating code when creating a grid of buttons?
body: <p>I am currently learning tkinter and wrote a code which creates a grid of 100 buttons which when clicked it disappears (I am yet to code that). However as seen below it is really inefficient. Is there any way to make this better and faster to write as I have coded each and every buttons with 1a,1b... and I want to know if there is a better way to do this.
  The project aim is to create a 10*10 board with buttons on each square and when clicked they disappear.</p>
  <pre><code># !/bin/python3
  from tkinter import *
  from PIL import ImageTk,Image
  
  root = Tk()
  root.title(&quot;Battleships&quot;)
  
  
  def buttonClick():
      COMMAND= True
      if COMMAND == True:
          del button1a
  
      
  # Creating the buttons
  image1 = ImageTk.PhotoImage(Image.open(&quot;/home/lukas/Downloads/Battleships boats/AircraftCarrier.png&quot;))
  label1 = Label(image=image1)
  label1.place(x=40, y=10)
  button1a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick) 
  button1b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button1j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button2j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button3j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button4j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button5j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button6j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button7j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button8j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button9j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10a = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10b = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10c = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10d = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10e = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10f = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10g = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10h = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10i = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  button10j = Button(root, text=&quot;&quot;, padx=20, pady=10, command=buttonClick)
  
  
  # Placing buttons onto the board
  button1a.grid(row=1, column=1)
  button1b.grid(row=1, column=2)
  button1c.grid(row=1, column=3)
  button1d.grid(row=1, column=4)
  button1e.grid(row=1, column=5)
  button1f.grid(row=1, column=6)
  button1g.grid(row=1, column=7)
  button1h.grid(row=1, column=8)
  button1i.grid(row=1, column=9)
  button1j.grid(row=1, column=10)
  button2a.grid(row=2, column=1)
  button2b.grid(row=2, column=2)
  button2c.grid(row=2, column=3)
  button2d.grid(row=2, column=4)
  button2e.grid(row=2, column=5)
  button2f.grid(row=2, column=6)
  button2g.grid(row=2, column=7)
  button2h.grid(row=2, column=8)
  button2i.grid(row=2, column=9)
  button2j.grid(row=2, column=10)
  button3a.grid(row=3, column=1)
  button3b.grid(row=3, column=2)
  button3c.grid(row=3, column=3)
  button3d.grid(row=3, column=4)
  button3e.grid(row=3, column=5)
  button3f.grid(row=3, column=6)
  button3g.grid(row=3, column=7)
  button3h.grid(row=3, column=8)
  button3i.grid(row=3, column=9)
  button3j.grid(row=3, column=10)
  button4a.grid(row=4, column=1)
  button4b.grid(row=4, column=2)
  button4c.grid(row=4, column=3)
  button4d.grid(row=4, column=4)
  button4e.grid(row=4, column=5)
  button4f.grid(row=4, column=6)
  button4g.grid(row=4, column=7)
  button4h.grid(row=4, column=8)
  button4i.grid(row=4, column=9)
  button4j.grid(row=4, column=10)
  button5a.grid(row=5, column=1)
  button5b.grid(row=5, column=2)
  button5c.grid(row=5, column=3)
  button5d.grid(row=5, column=4)
  button5e.grid(row=5, column=5)
  button5f.grid(row=5, column=6)
  button5g.grid(row=5, column=7)
  button5h.grid(row=5, column=8)
  button5i.grid(row=5, column=9)
  button5j.grid(row=5, column=10)
  button6a.grid(row=6, column=1)
  button6b.grid(row=6, column=2)
  button6c.grid(row=6, column=3)
  button6d.grid(row=6, column=4)
  button6e.grid(row=6, column=5)
  button6f.grid(row=6, column=6)
  button6g.grid(row=6, column=7)
  button6h.grid(row=6, column=8)
  button6i.grid(row=6, column=9)
  button6j.grid(row=6, column=10)
  button7a.grid(row=7, column=1)
  button7b.grid(row=7, column=2)
  button7c.grid(row=7, column=3)
  button7d.grid(row=7, column=4)
  button7e.grid(row=7, column=5)
  button7f.grid(row=7, column=6)
  button7g.grid(row=7, column=7)
  button7h.grid(row=7, column=8)
  button7i.grid(row=7, column=9)
  button7j.grid(row=7, column=10)
  button8a.grid(row=8, column=1)
  button8b.grid(row=8, column=2)
  button8c.grid(row=8, column=3)
  button8d.grid(row=8, column=4)
  button8e.grid(row=8, column=5)
  button8f.grid(row=8, column=6)
  button8g.grid(row=8, column=7)
  button8h.grid(row=8, column=8)
  button8i.grid(row=8, column=9)
  button8j.grid(row=8, column=10)
  button9a.grid(row=9, column=1)
  button9b.grid(row=9, column=2)
  button9c.grid(row=9, column=3)
  button9d.grid(row=9, column=4)
  button9e.grid(row=9, column=5)
  button9f.grid(row=9, column=6)
  button9g.grid(row=9, column=7)
  button9h.grid(row=9, column=8)
  button9i.grid(row=9, column=9)
  button9j.grid(row=9, column=10)
  button10a.grid(row=10, column=1)
  button10b.grid(row=10, column=2)
  button10c.grid(row=10, column=3)
  button10d.grid(row=10, column=4)
  button10e.grid(row=10, column=5)
  button10f.grid(row=10, column=6)
  button10g.grid(row=10, column=7)
  button10h.grid(row=10, column=8)
  button10i.grid(row=10, column=9)
  button10j.grid(row=10, column=10)
  
  
  
  
  root.mainloop()
  </code></pre>