One of the ways to achieve this is using StringVar
:
def capture(*args):
if e.get():
button['state'] = 'normal'
else:
button['state'] = 'disabled'
var = StringVar()
e = Entry(root, font = 20,borderwidth=5,textvariable=var)
e.pack()
var.trace('w',capture)
trace()
will call the provided callback each time the value of var
is changed.
The second way is to use bind
:
def capture():
if e.get():
button['state'] = 'normal'
else:
button['state'] = 'disabled'
e = Entry(root, font = 20,borderwidth=5)
e.pack()
e.bind('<KeyRelease>',lambda e: capture()) # Bind keyrelease to the function
With bind
, each time the key is released the function is called, whatever the key maybe. This might be a bit better because you are not creating a StringVar
just for the sake of using its trace
.