0

I have the following code which not working way i thought it would, but i am only beginner. can someone please explain how i can get the txt to clear before entering the next. at moment if i type hi i get right response but i want that to clear before get next response.

import tkinter

def show_data():
    txtBox = ent.get()

    if txtBox == ("hi" or "hello"):
        txt.delete(0.0, END)
        txt.insert(0.0, sentense)
    elif txtBox == ("i am good"):
        txt.delete(0.0, END)
        txt.insert(0.0, sentense1)
    else:
        txt.delete(0.0, END)
        txt.insert(0.0, sentence3)




window = tkinter.Tk()
window.configure(background="#18e0d9")
window.title("Project One")
window.geometry("300x300")

sentense = ("Hi! How are you?")
sentense1 = ("I'm glad to hear it")
sentence3 = ("i dont understand")


photo = tkinter.PhotoImage(file = 'title.gif')

w = tkinter.Label(window, image=photo)


lblInst = tkinter.Label(window, text="HOW CAN I HELP YOU TODAY?", 
fg="#383a39", bg="#18e0d9", font="bolder")



ent = tkinter.Entry(window, width=38)
btn = tkinter.Button(window, text="submit", fg="#ffffff", bg="#383a39", command=show_data)
txt = tkinter.Text(window, width=29, height=6, bg="#18e0d9")


txt.pack(side="bottom", pady=15)
w.pack()
lblInst.pack(pady=5)
ent.pack(pady=5)
btn.pack(pady=5)



window.mainloop()
Epic Guy
  • 15
  • 2
  • can you explain it further because it clear the text widget before it insert – AD WAN Feb 28 '18 at 10:38
  • yes since i added the code to clear e.g. the txt.delete bit now i dont even get a result appear at all when press submit – Epic Guy Feb 28 '18 at 10:46

1 Answers1

0

Use the syntax correctly as in:

text = tkinter.Text()
text.insert('1.0', 'template') # add template from the start point
text.delete('1.0', 'end') # delete from start to end, entirely
Nae
  • 14,209
  • 7
  • 52
  • 79