1 回答

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超3個(gè)贊
給你。您正在使用isdigitfor Pbut%P是整個(gè)文本(包括剛剛按下的內(nèi)容),所以我們切換到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
添加回答
舉報(bào)