title: How to pass two or more arguments to a Button command?
body: <p>I'd like to pass 2 variable arguments in a function to be assigned to a <code>Button</code> <code>command</code>. These variables change within a <code>for</code> loop that also creates the buttons.</p>
  
  <p>Mostly inspired by some of the top answers <a href="https://stackoverflow.com/questions/5767228/why-is-button-parameter-command-executed-when-declared/47980499#47980499">here</a> and <a href="https://stackoverflow.com/questions/6920302/how-to-pass-arguments-to-a-button-command-in-tkinter/47996979#47996979">here</a>, here are my fail attempts at trying to solve this problem based on what I read:</p>
  
  <p>I tried using <code>partial</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>self.dct[(i, j)] = Button(command=partial(self.on_click, i, j))
  </code></pre>
  
  <p>Another try:</p>
  
  <pre class="lang-py prettyprint-override"><code>self.dct[(i, j)] = Button(command=partial(partial(self.on_click, i), j))
  </code></pre>
  
  <p>And another:</p>
  
  <pre class="lang-py prettyprint-override"><code>self.dct[(i, j)] = Button(command=partial(self.on_click, [i, j]))
  </code></pre>
  
  <p>.. Guess what?</p>
  
  <pre class="lang-py prettyprint-override"><code>tup = [i, j]
  self.dct[(i, j)] = Button(command=partial(self.on_click, tup))
  </code></pre>
  
  <p>And then, <code>lambda</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>self.dct[(i, j)] = Button(command=lambda i=i, j=j: self.on_click(i, j))
  </code></pre>
  
  <p>Here's my code:</p>
  
  <pre class="lang-py prettyprint-override"><code>import tkinter as tk
  
  from functools import partial
  
  
  class Board(tk.Frame):
      board = None
      images = None
      tile = None
  
      def __init__(self, parent):
          tk.Frame.__init__(self, parent)
          self.tile = {}
          for i in range(10):
              for j in range(10):
                  self.tile[(i, j)]['btn_obj'] = tk.Button(self.board, command=partial(partial(self.on_click, i), j))
  
      def on_click(self, i, j):
          print("X: {}, Y:{}".format(j, i))
  
  </code></pre>
  
  <p><code>partial</code> always causes an error like this:</p>
  
  <pre class="lang-py prettyprint-override"><code>TypeError: on_click() takes 2 positional arguments but 3 were given
  </code></pre>
  
  <p>It's always mismatched number of arguments.</p>
  
  <p>Meanwhile, <code>lambda</code> gets the wrong value of the variables, causing something of an error in <code>tkinter</code>'s part.</p>