示例代码:
import tkinter as tk
win=tk.Tk()
win.geometry('300x100')
win.title('test')
def lena(num):
for i in range(len(a.get())):
num = a.get()[i]
# 判断字符是否为isalnum(数字、字母)、中文字符(编码范围:'\u4e00'-'\u9fa5')、count统计数量
if num not in ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'] or ('\u4e00' <= num <= '\u9fa5') == True \
and num != '' or a.get()[0].isdigit() == False or a.get().count('.') > 1:
print(i, type)
a.delete(i, 'end')
break
#限制输入前两位数都为0
if a.get() == '00':
a.delete(0, 'end')
a=tk.Entry(win,width=18)
a.pack()
a.bind('<KeyRelease>', lena) #任意按键松开
win.mainloop()
效果如下: