from tkinter import *
root = Tk()
root.geometry('200x200+300+300')
sv = StringVar()
def callback(sv):
if not sv.get()[-1].isdigit():
sv.set(sv.get()[:-1])
sv.trace("w", lambda name, index, mode, sv=sv: callback(sv))
e = Entry(root, textvariable=sv)
e.pack()
root.mainloop()