title: How to bind 2 functions to a button in tkinter?
body: <p>I am trying to make an application where if I left click a button in a grid it changes the images to 1.jpg and when it is right clicked it changes to 2.jpg. I tried it several times but the image is not changing on right click.</p>
  <p>This is how the grid looks like:
  <a href="https://i.stack.imgur.com/D3kks.jpg" rel="nofollow noreferrer">image</a></p>
  <p>The code:</p>
  <pre><code>from tkinter import *
  from PIL import ImageTk, Image
  
  WIN = Tk()
  WIN.geometry(&quot;280x660+300+10&quot;)
  
  Button_Frame = Frame(WIN,width=399,height=100)
  Button_Frame.pack()
  Main = Frame(WIN,width=399,height=399)
  Main.pack()
  
  img1 = Image.open(&quot;2.jpg&quot;)
  img1 = img1.resize((57, 57), Image.ANTIALIAS) 
  photo1 = ImageTk.PhotoImage(img1) 
  
  img2 = Image.open(&quot;3.jpg&quot;)
  img2 = img2.resize((57, 57), Image.ANTIALIAS) 
  photo2 = ImageTk.PhotoImage(img2) 
  
  button_list = []
  type_click = &quot;&quot;
  
  for i in range(49):
      f1 = Frame(Main,width=40,height=40,bg=&quot;black&quot;)
      b = Button(f1, text = &quot;&quot;,borderwidth=4,bg=&quot;white&quot;)
      button_list.append(b)
  
      def first(k):
          if type_click == &quot;left&quot;:
              button_list[k].configure(image=photo1)
          elif type_click == &quot;right&quot;:
              button_list[k].configure(image=photo2)
  
      def left(event):
          global type_click
          type_click = &quot;left&quot;
          print(&quot;left&quot;)
      def right(event):
          global type_click
          type_click = &quot;right&quot;    
          print(&quot;right&quot;)  
  
      b.configure(command=lambda k=i:first(k))
      b.bind(&quot;&lt;Button-1&gt;&quot;,left)
      b.bind(&quot;&lt;Button-3&gt;&quot;,right)
      f1.rowconfigure(0, weight = 1)
      f1.columnconfigure(0, weight = 1)
      f1.grid_propagate(0)
      f1.grid(row = i//7, column = i%7)
  
  
     # b.bind(&quot;&lt;Button-1&gt;&quot;,lambda k=i:first(k))
      b.grid(sticky = &quot;NWSE&quot;)
      
  WIN.mainloop()
  </code></pre>
  <p><strong>Please tell me where am I going wrong</strong></p>