I have a simple interface set up using Tkinter.I have a drop down box, which is irrelevant. I also have two entry widget boxes. What I want to happen is for the second one to initialize as DISABLED, but AS SOON AS any text is entered in the first box I want the second one to become active. For some reason, my second box does not activate when text is entered into the first box. Any help would be great. Thanks!
from Tkinter import *
import tkMessageBox
import os
if __name__ == "__main__":
root = Tk()
root.title("ShotBot")
root["padx"] = 40
root["pady"] = 20
root.geometry('500x200-400+200')
root.resizable(FALSE,FALSE)
textFrame = Frame(root)
#Create and place Option List
var=StringVar()
choices = ['a','b','c']
var.set(choices[0])
entryWidget = OptionMenu(root, var, *choices)
entryWidget["width"] = 30
entryWidget.pack(side="top")
#Create and Place Text Field
entryWidget2= Entry(textFrame)
entryWidget2["width"] = 30
entryWidget2.pack(side="top")
#Create and Place Text Field
entryWidget3 = Entry(textFrame)
entryWidget3["width"] = 30
entryWidget3.pack(side="top")
textFrame.pack()
button = Button(root, text="Submit")
button.pack()
if entryWidget2.get().strip()=="":
entryWidget3["state"]=DISABLED
else:
entryWidget3["state"]=NORMAL
root.mainloop()
The simplest thing to do is assign a value to the
textvariableoption of the first entry widget, place a trace on the variable, and then enable or disable the other widget depending on the current value of the variable. Something like this: