马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from tkinter import *
root = Tk()
frame = Frame(root)
frame.pack(padx=10,pady=10)
v1 = StringVars()
v2 = StringVars()
v3 = StringVars()
def test(content):
if content.isdigit():
return True
else:
return False
testCMD = root.register(test)
Entry(frame,textvariable=v1,width=10,validate="key",\
validatecommand=(testCMD,'%p')).grid(row=0,column=0)
Label(frame,text="+").grid(row=0,column=1)
Entry(frame,textvariable=v2,width=10,validate="key",\
validatecommand=(textCMD,'%P')).gird(row=0,column=2)
Label(frame,text="=").gird(row=0,column=3)
Entry(farme,textvariable=v3,width=10,validate="key",\
validatecommand=(textCMD,'%P')).gird(row=0,column=4)
def calc():
result = int(v1.get()) + int(v2.get())
v3.set(result)
Button(frame,text="计算结果",command=calc).grid(row=1,column=2,pady=5)
mainloop()
报错信息:
Traceback (most recent call last):
File "C:\Users\cilu\Desktop\备用\备用(2).py", line 8, in <module>
v1 = StringVars()
NameError: name 'StringVars' is not defined
不是 StringVars,是 StringVar
|