我在互联网上找到了源代码 一个简单的程序,用于创建带有选项的窗口 从键盘输入数学运算并显示 结果。这是代码:
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()
我收到错误:
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
请帮忙。我开始学习 Python,但我不知道解决方案。
最佳答案
您报告的错误很清楚,
“...绑定(bind)中未指定事件”
改变这个
entry.bind('<event>', evaluate)
有了这个
entry.bind("<Return>",evaluate)
关于python - 如何修复 "- _tkinter.TclError: no events specified in binding",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56343229/