How to keybind the return to the "=" code: Python
<p>I am trying to keybind the enter key to "=".</p>

<p>With the code I have now, I get an error when i put in two numbers and press enter, the error is:</p>

<pre><code>Exception in Tkinter callback
Traceback (most recent call last):
line 1550, in __call__
return self.func(*args)

line 68, in &lt;lambda&gt;
root.bind('&lt;Return&gt;', lambda x: Calculator.calcu('='))
TypeError: calcu() missing 1 required positional argument: 'entry_num'
</code></pre>

<p>The fact that the random window pops up at the start is just evidence that it's not working I guess. I believe that if the root window problem gets fixed, it could fix the key bind problem.</p>

<p>I get that error as I press enter, there is also a random window that opens up as I run the code as well if that helps anyone helping trying to solve the problem, please help me I'm really stuck.</p>

<p><strong>THE OVERALL PROBLEM IS:</strong>
I don't know how to key bind the enter key on my keyboard to "=" and make the entry get entered by doing so.</p>

<p><a href="http://i.stack.imgur.com/OgSvz.png" rel="nofollow">This is what I get when i run my code(picture)</a></p>

<pre><code>    from __future__ import division
from functools import partial 
from math import * 
import tkinter as tk 
from tkinter import *  
root=Tk()
class Calculator(tk.Tk): 
def __init__(self):     
    tk.Tk.__init__(self)
    self.buttons_layout()       
    self.title("Thomas's calc") 
    textb = Entry(root)

def calcu(self,entry_num):

    if entry_num == "=":  
        try: 
            total=eval(self.textb.get()) 
            self.textb.insert(tk.END," = "+str(total)) 
        except: 
            self.textb.insert(tk.END, " - Invalid Calculation - ") 


    elif entry_num == "del":
        self.txt=self.textb.get()[:-1]
        self.textb.delete(0,tk.END)
        self.textb.insert(0,self.txt)

    elif entry_num == "C":
        self.textb.delete(0,END) 

    elif entry_num == "i":      
        infob= Toplevel(self.textb.insert(tk.END, ""))   
        infob = Label(infob, text="Thomas, Calculator").pack()  


    else: 
        if "=" in self.textb.get(): 
            self.textb.delete(tk.END)           
        self.textb.insert(tk.END, entry_num)

def buttons_layout(self): 

    self.textb = tk.Entry(root, width=66, fg="white", bg="black", state="normal") #text color = fg // background colour bg // sets the entry box specs
    self.textb.grid(row=0, column=0, columnspan=5) 

    buttona="groove"                       

    ycol = 0                         

    xrow = 1                                     

    button_list = ["1","2","3","+","C",
                   "4","5","6","-","del",       
                   "7","8","9","/","",
                   "0",".","i","*","="]

    for button in button_list:             
        calc1=partial(self.calcu, button) 
        tk.Button(root,text=button,height=4,command=calc1,bg="aquamarine", fg="red",width=10,state="normal",relief=buttona).grid(
            row=xrow, column=ycol)
        ycol= ycol + 1 
        if ycol &gt; 4:  
            ycol=0  
            xrow= xrow + 3 

class key_binding():
    root.bind('&lt;Return&gt;', lambda x: Calculator.calcu('='))

end=Calculator()
end.mainloop()
root.mainloop()
</code></pre>

<p>THE KEYBIND IS AT THE BOTTOM OF MY CODE BY THE WAY</p>

<p>This should work. I've also got rid of the second window that wasn't needed</p>

<pre><code>from __future__ import division
from functools import partial 
from math import * 
import tkinter as tk 
from tkinter import *  
#root=Tk()
class Calculator(tk.Tk): 
    def __init__(self):     
        tk.Tk.__init__(self)
        self.buttons_layout()       
        self.title("Thomas's calc") 
        textb = Entry(self)
        self.bind('&lt;Return&gt;', lambda x: self.calcu('='))

    def calcu(self,entry_num):

        if entry_num == "=":  
            try: 
                total=eval(self.textb.get()) 
                self.textb.insert(tk.END," = "+str(total)) 
            except: 
                self.textb.insert(tk.END, " - Invalid Calculation - ") 


        elif entry_num == "del":
            self.txt=self.textb.get()[:-1]
            self.textb.delete(0,tk.END)
            self.textb.insert(0,self.txt)

        elif entry_num == "C":
            self.textb.delete(0,END) 

        elif entry_num == "i":      
            infob= Toplevel(self.textb.insert(tk.END, ""))   
            infob = Label(infob, text="Thomas, Calculator").pack()  


        else: 
            if "=" in self.textb.get(): 
                self.textb.delete(tk.END)           
            self.textb.insert(tk.END, entry_num)

    def buttons_layout(self): 

        self.textb = tk.Entry(self, width=66, fg="white", bg="black", state="normal") #text color = fg // background colour bg // sets the entry box specs
        self.textb.grid(row=0, column=0, columnspan=5) 

        buttona="groove"                       

        ycol = 0                         

        xrow = 1                                     

        button_list = ["1","2","3","+","C",
                       "4","5","6","-","del",       
                       "7","8","9","/","",
                       "0",".","i","*","="]

        for button in button_list:             
            calc1=partial(self.calcu, button) 
            tk.Button(self,text=button,height=4,command=calc1,bg="aquamarine", fg="red",width=10,state="normal",relief=buttona).grid(
                row=xrow, column=ycol)
            ycol= ycol + 1 
            if ycol &gt; 4:  
                ycol=0  
                xrow= xrow + 3 

#class key_binding():
#    root.bind('&lt;Return&gt;', lambda x: Calculator.calcu('='))

end=Calculator()
end.mainloop()
#root.mainloop()
</code></pre>

python user-interface tkinter calculator