Rob90
Rob90

Reputation: 33

How to fix "- _tkinter.TclError: no events specified in binding"

I found the source code somewhere on the internet a simple program to create a window with the option entering mathematical operations and displaying from the keyboard the result.This is code:

import tkinter as tk
from math import *

def evaluate(event):
    res.configure(text="Result: " + str(eval(entry.get())))

w = tk.Tk()
tk.Label(w, text="Your Expression:").pack()
entry = tk.Entry(w)
entry.bind("event", evaluate)
entry.pack()
res = tk.Label(w)
res.pack()
w.mainloop()

I'm getting an error:

C:\Users\rob\PycharmProjects\untitled2\venv\Scripts\python.exe "C:/Users/rob/Desktop/new test.py" Traceback (most recent call last): File "C:/Users/rob/Desktop/new test.py", line 12, in entry.bind("", evaluate) File "C:\Users\rob\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py", line 1248, in bind return self._bind(('bind', self._w), sequence, func, add) File "C:\Users\rob\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py", line 1203, in _bind self.tk.call(what + (sequence, cmd)) _tkinter.TclError: no events specified in binding

Please help. Im starting learning Python and I don't know a solution.

Upvotes: 3

Views: 5922

Answers (1)

1966bc
1966bc

Reputation: 1308

it's clear in your reported error,

"...no events specified in binding"

change this

    entry.bind('<event>', evaluate)

with this

    entry.bind("<Return>",evaluate)

enter image description here

Upvotes: 8

Related Questions