Problems displaying input data into a textbox using tkinter,python Problems displaying input data into a textbox using tkinter,python tkinter tkinter

Problems displaying input data into a textbox using tkinter,python


The issue occurs because of the lines -

songList = Text(frame, wrap=NONE, bd=0,        xscrollcommand=xscrollbar.set,        yscrollcommand=yscrollbar.set,        textvariable=textoutput1)

You cannot set textvariable for Text widget .

You should rather use Text.insert() method with END to insert your songs to the end in the Text widget. Example -

from tkinter import *from tkinter import ttkdef textMethod(*args):    copytext = textinput1.get()    songList.insert(END, copytext + '\n')root = Tk()root.title("Naynt Music Database")frame = ttk.Frame(root,padding = "12 12 12 12")frame.grid(column=0,row=1,sticky="N,S,E,W")frame.columnconfigure(0,weight=1)frame.rowconfigure(0,weight=1)textinput1 = StringVar()textoutput1 = StringVar()text_entry = ttk.Entry(frame,width=20,textvariable = textinput1)text_entry.grid(row=1,column=0,sticky=(W,E))ttk.Button(frame,text="Add songname",command=textMethod).grid(column=1,row=1)songListFrame = Frame(frame, bd=2, relief=SUNKEN)frame.grid_rowconfigure(0, weight=1)frame.grid_columnconfigure(0, weight=1)xscrollbar = Scrollbar(frame, orient=HORIZONTAL)xscrollbar.grid(row=3, column=0, sticky=E+W)yscrollbar = Scrollbar(frame)yscrollbar.grid(row=2, column=1, sticky=N+S)songList = Text(frame, wrap=NONE, bd=0,            xscrollcommand=xscrollbar.set,            yscrollcommand=yscrollbar.set)songList.grid(row=2, column=0, sticky=N+S+E+W)xscrollbar.config(command=songList.xview)yscrollbar.config(command=songList.yview)frame.pack()root.mainloop()

Added a newline to the line as well, so that each song comes in a new line .


The Text widget doesn't use a text variable. To read the text from the widget, use its get() method. I recommend John Shipman's intro to tkinter at infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html