0
我正在嘗試使用16個字符的限制進行輸入。 到目前爲止,我有這樣的事情:Tkinter - validatecommand +退格
import tkinter as tk
rt = tk.Tk()
def tr_input():
a = e['textbox']
b = a.get()
print(b)
if "\b" in b:
return True
if "\n" in b:
calculate()
elif len(b)>16:
return False
return True
e = { "textbox":tk.Entry(rt,validate = "all",validatecommand=tr_input) }
calculate()
對在條目數量計算,並將其顯示在另一個標籤
它工作正常,並阻止任何進一步的字符後從被輸入第16個。但是,它也可以防止通過退格刪除字符,我不知道如何......沒有這樣做。
有誰知道我該如何解決這個問題?
編輯:具體來說,我需要能夠找出是否最後一次按下按鈕是退格