Kpras
Kpras

Reputation: 63

tkinter insert into output text field (output.insert()) is not working

I have a Tkinter GUI, Where i have a input text field and output text field and
a button. User typying anything in text field and clicking the button then it have to be printed in the output field. But here the input values are not inserting into the output field.

from tkinter import *



base = Tk()
base.title('Demo')
base.geometry("400x500")
base.resizable(width=FALSE, height=FALSE)


outputwindow = Text(base, bd=0, bg="white", height="8", width="50", font="Arial",)
# outputwindow.insert(END, "Connecting to your partner..\n")

outputwindow.config(state=DISABLED)

#Bind a scrollbar to the Chat window
scrollbar = Scrollbar(base, command=outputwindow.yview, cursor="heart")
outputwindow['yscrollcommand'] = scrollbar.set


EntryBox = Text(base, bd=0, bg="white",width="29", height="5", font="Arial")


def ClickAction():

    input=EntryBox.get("1.0",END)
    print(input)
    EntryBox.delete('1.0',END)
    outputwindow.insert(END, input)


SendButton = Button(base, font=30, text="Send", width="12", height=5,bd=0, bg="lightgray", command=ClickAction)




#Place all components on the screen
scrollbar.place(x=376,y=6, height=386)
outputwindow.place(x=6,y=6, height=386, width=370)
EntryBox.place(x=128, y=401, height=90, width=265)
SendButton.place(x=6, y=401, height=90)

base.mainloop()

I have tried other programs for this same purpose, it works fine. But here i can't process and i can't find the issue.(i'm just learning tkinter)

Upvotes: 0

Views: 1688

Answers (1)

fhdrsdg
fhdrsdg

Reputation: 10532

When a text widget is disabled you can't put text in it, not even with .insert() or .delete(). To modify the text you need to change the state to normal, insert your text and then change the state back to disabled:

outputwindow.config(state=NORMAL)
outputwindow.insert(END, input)
outputwindow.config(state=DISABLED)

Upvotes: 1

Related Questions