1 回答
TA贡献1803条经验 获得超3个赞
给你。您正在使用isdigitfor Pbut%P是整个文本(包括刚刚按下的内容),所以我们切换到isnumeric. 如果我正确理解了你的指示,你就忘了处理entry_d.
我用 arange而不是len(P) > 0 and len(P) < 5,而且range是正确的。
def only_numeric_input(P):
if len(P) in range(1,5) and P.isnumeric():
#if we have 1 to 4 numeric characters
# enable entry_c, and unlink entry c & d content from entry b
entry_c.config(textvariable=var_c, state='normal')
entry_d.config(textvariable=var_c)
elif not P:
#if we have no characters
# disable entry_c, and link entry c & d content to entry b
entry_c.config(textvariable=var_b, state='disabled')
entry_d.config(textvariable=var_b)
else:
#everything else
return False
return True
添加回答
举报