【发布时间】:2012-03-21 13:27:25
【问题描述】:
def chkDay(x, size, part):
dayre = re.compile('[0-3][0-9]') # day digit 0-9
if (dayre.match(x)):
if (len(x) > size):
return tkMessageBox.showerror("Warning", "This "+ part +" is invalid")
app.destroy
else:
tkMessageBox.showinfo("OK", "Thanks for inserting a valid "+ part)
else:
tkMessageBox.showerror("Warning", part + " not entered correctly!")
root.destroy
#when clicked
chkDay(vDay.get(),31, "Day")
#interface of tkinter
vDay = StringVar()
Entry(root, textvariable=vDay).pack()
问题:
- 没有验证,我可以输入大于 31 的一天,它仍然显示:OK
- 当我调用 root.destroy 时,root(应用程序)没有关闭
【问题讨论】:
-
如何使用code停止tk应用?
-
if x.isdigit() and int(x) <= size: print 'yup, correct input.' -
在您使用
len的代码中,您确定不是要放入int吗?len('99')是 2,小于 31,所以它会通过你的测试。 -
root.destroy应该是root.destroy()。没有括号,您就不会调用该方法。 -
你有
app.destroy和root.destroy,都没有括号。但是app或root是哪个?
标签: python regex validation tkinter