Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文本插入python tkinter文本小部件_Python_Tkinter_Char - Fatal编程技术网

将文本插入python tkinter文本小部件

将文本插入python tkinter文本小部件,python,tkinter,char,Python,Tkinter,Char,我一直在制作一个响应用户输入的程序。当我运行它时,我的代码不会将响应插入文本小部件。我得到一个错误: TypeError:插入缺少1个必需的位置参数:“chars” 我的代码是: global stuff stuff = open("Dictionary.txt", "r") global contents contents = stuff.read() stuff.close() from tkinter import * dictionary = {"chungus": "Come at

我一直在制作一个响应用户输入的程序。当我运行它时,我的代码不会将响应插入文本小部件。我得到一个错误:

TypeError:插入缺少1个必需的位置参数:“chars”

我的代码是:

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()

我错过了什么吗?

回答起来很简单。在您的代码中,您已经编写了text.insertEND,也就是说,您之前在另一个区域中键入了text.insertmeans。我认为这只是因为您在键入代码时遗漏了一些内容。试着复制代码的正确版本,在代码的末尾,在您得到问题的行之前。另外,我建议您在代码中添加注释,因为这样可以更容易地查看问题所在

注释掉三个填充语句2、4和5,并在text.insertEND中添加结尾,这意味着在下面的PNX回答中,每19个填充语句都有效。输入dict中的值将正确响应,并在出现错误时收到“无回复”消息。请共享整个错误消息。不要使用import*,这很少是个好主意。请阅读中的建议。这对于调试以及在失败时提出更好的问题都非常有用。