from Tkinter import * class MyClass: def __init__(self, parent): self.myParent = parent self.portVar = IntVar() self.portVar.set(111) port_validator = self.myParent.register(self._validate) self.myEntry = Entry(self.myParent, width=9, textvariable=self.portVar, validate='all', validatecommand=(port_validator,'%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W')) self.myEntry.pack(side=TOP) def _validate(self, d, i, P, s, S, v, V, W): print "OnValidate: d='%s' i='%s' P='%s' s='%s' S='%s' v='%s' V='%s' W='%s'" % (d, i, P, s, S, v, V, W) return P.isdigit() root = Tk() myclass = MyClass(root) root.mainloop()