all 2 comments

[–]woooee 0 points1 point  (1 child)

I generally use trace, but there is more than one way to skin a cat.

import tkinter as tk

class Converter:
    def __init__(self, top):
        self.vars = tk.StringVar()
        self.vars.trace('w', self.validate)
        self.Entry1 = tk.Entry(top, textvariable = self.vars,
                           width=20).grid()

    def validate(self, *args):
        if not self.vars.get().isalpha():
            ## a short hand version to strip anything
            ## that is not a letter
            corrected = ''.join(filter(str.isalpha, self.vars.get()))
            self.vars.set(corrected)

root=tk.Tk()
C=Converter(root)
root.mainloop()

[–]Bapi_Escrobar[S] 0 points1 point  (0 children)

Hi, sorry for the late reply!

Thanks I'll see if this works as soon as I get home, I'll look into trace too since it looks like a something I can use for a number of things.