from tkinter import *

# Demonstrates "focus" method and
# Entry box enabled/disabled


window = Tk()

window.title("Welcome to Tkinter!")
window.geometry('400x300+30+200')
#window.configure(bg = "#8080F0")

# ------------------------------
# labels specifications

# One label is a pure entry box description
lbl1 = Label(window, text="Enter name:")
lbl1.grid(column=0, row=0)

# The other label presents the result of actions
lbl2 = Label(window, text="            ")
lbl2.grid(column=1, row=1)

# ------------------------------
# Entry box specifications

def entryEnter(event):
    atext = "Hello, " + txtEntry.get() + "!"
    lbl2.configure(text = atext)

txtEntry = Entry(window, width=20)
txtEntry.grid(column=1, row=0)
txtEntry.bind('<Return>', entryEnter)

txtEntry.focus()

# ------------------------------
# Action button specifications

def clickedBtn():
    atext = "Hello, " + txtEntry.get() + "!"
    lbl2.configure(text = atext)

btn = Button(window, text="Make Greeting", command=clickedBtn)
btn.grid(column=2, row=0)


# ------------------------------
# Button which works as a switch
# Entry widget may be Enabled or Disabled

enabledEntry = True

def clickedEnDis():
    global enabledEntry
    enabledEntry = not enabledEntry
    if enabledEntry:
        txtEntry.configure(state ='normal')
        disBtn.configure( text = "Disable entry" )
    else:
        txtEntry.configure(state ='disabled')
        disBtn.configure( text = "Enable entry " )

disBtn= Button(window, text="Disable entry", command=clickedEnDis )
disBtn.grid(column=0, row=2)



window.mainloop()

