我一直在尝试在 Python 33 上使用 Tkinter 制作一个毕达哥拉斯定理计算器,但我遇到了一个小问题。
这是我的代码 -
from tkinter import *
import math
root = Tk()
L1 = Label(root, text="A = ")
L1.pack()
E1 = Entry(root, bd =5)
E1.pack()
L2 = Label(root, text="B = ")
L2.pack()
E2 = Entry(root, bd =5)
E2.pack()
asq = E1**2
bsq = E2**2
csq = asq + bsq
ans = math.sqrt(csq)
def showsum():
tkMessageBox.showinfo("Answer =", ans)
B1 = tkinter.Button(root, text="Click This To Calculate!", command = showsum())
B1.pack()
root.mainloop()
这是我的错误信息 -
Traceback (most recent call last):
File "C:/Users/Dale/Desktop/programming/Python/tkinterpythagoras.py", line 18, in <module>
asq = E1**2
TypeError: unsupported operand type(s) for ** or pow(): 'Entry' and 'int'
请不要对我粗鲁。我是 Tkinter 的初学者!