title: How to add key binding?
body: <p>None of the other stackoverflow suggestions, nor any other outside documentation has shown me how to successfully bind a key to a function. Below are links I've tried (code copied and pasted) and had no luck with. I see many people suggesting focus as a reason for failure, as though the frame containing the button isn't the user's target and therefore isn't active; nothing has come from this however. Below are links I have tried:</p>
  
  <p><a href="http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm" rel="nofollow noreferrer">http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm</a></p>
  
  <p><a href="https://softwareengineering.stackexchange.com/questions/213935/why-use-classes-when-programming-a-tkinter-gui-in-python">https://softwareengineering.stackexchange.com/questions/213935/why-use-classes-when-programming-a-tkinter-gui-in-python</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13326940/python-tkinter-how-to-bind-key-to-a-button">python tkinter how to bind key to a button</a></p>
  
  <p><a href="http://www.java2s.com/Code/Python/GUI-Tk/SetButtontogetfocus.htm" rel="nofollow noreferrer">http://www.java2s.com/Code/Python/GUI-Tk/SetButtontogetfocus.htm</a></p>
  
  <p><a href="https://stackoverflow.com/questions/20832909/how-to-bind-a-keypress-to-a-button-in-tkinter">How to bind a keypress to a button in Tkinter</a></p>
  
  <p>I am running Python 3.6 in PyCharm 5.0.4.</p>
  
  <p>The code in the links above are what I've been using/modifying to see how it works but not a single attempt has ended with an action being carried out. The furthest I've gotten is an error message.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT: code I am using below (from most recent link)</p>
  
  <pre><code>from tkinter import *
  root = Tk()
  
  def LeftTurn(event):
      print('left')
  frame=Frame(root, width=100, height=100)
  frame.bind("&lt;Left&gt;", LeftTurn)   #Binds the "left" key to the frame and exexutes yourFunction if "left" key was pressed
  frame.pack()
  
  
  root.geometry("640x480")
  root.title("Rover ")
  
  
  root.mainloop()
  </code></pre>
  
  <p>I also tried this one (below)</p>
  
  <pre><code>from tkinter import *
  
  root = Tk()
  
  def yourFunction(event):
      print('left')
  
  frame = Frame(root, width=100, height=100)
  
  frame.bind("&lt;Left&gt;",yourFunction)   #Binds the "left" key to the frame and exexutes yourFunction if "left" key was pressed
  frame.pack()
  
  root.mainloop()
  </code></pre>