0

I have been making a program that responds to a user input. When I run it my code doesn't insert the response into the text widget. I get the error:

TypeError: insert() missing 1 required positional argument: 'chars'

My code is:

global stuff
stuff = open("Dictionary.txt", "r")
global contents
contents = stuff.read()
stuff.close()
from tkinter import *

dictionary = {"chungus": "Come at me chungus ... you wanna go?",
                      "hi": "It's good to see you!", "bot": "No - you're the BOT"}

def output():
    TT = entry.get()
    text.delete(0.0, END)
    try:
        meaning = dictionary[TT]
    except:
        meaning = "We do not have a reply for this yet..."
    text.insert(meaning)

def words():
    TT = (contents)
    text.delete(0.0, END)
    meaning = (TT)
    text.insert(END, meaning)




global window
window = Tk()
window.title("WFR")
label1 = Label(window, text="Enter stuff for reply (No caps):    ")
label1.grid(row=0, column=0, sticky=W)
entry = Entry(window, width=35, bg="light green")
entry.grid(row=1, column=0, sticky=W)
button1 = Button(window, text="SUBMIT", width=8, command=output)
button1.grid(row=3, column=0, sticky=W)
text = Text(window, width=60, height=20, wrap=WORD, background="yellow")
text.grid(row=2, column=0, sticky=W)
menubar = Menu(window)
firstmenu = Menu(menubar, tearoff=0)
firstmenu.add_command(label="Type What?", command=words)
menubar.add_cascade(label="Options", menu=firstmenu)
window.config(menu=menubar)
window.mainloop()

Have I missed something?

3
  • Commenting out the three stuff statements (2,4 and 5) and adding the END to the text.insert(END, meaning) at 19 - per PNX's answer below will work. Entering values from the dict respond correctly and get the no reply message when an error. Commented Mar 13, 2020 at 19:12
  • Please share the entire error message. Don’t use import *, it’s rarely a good idea. Commented Mar 14, 2020 at 2:38
  • Read the advice in stackoverflow.com/help/minimal-reproducible-example. It is great for debugging as well as asking better questions if you fail. Commented Mar 15, 2020 at 22:34

1 Answer 1

1

This is something quite simple to answer. In your code you have written text.insert(END, meaning), earlier in a different area you have typed text.insert(meaning). I think this is simply you missing something as you type your code. Try to copy the correct version of code (with the END, before it) in the line where you are getting your issue. Also, may I suggest adding comments to your code as it makes it a lot easier to see where the issue is.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.