【发布时间】:2020-12-27 15:41:51
【问题描述】:
我正在使用 Tkinter 模块创建一个 GUI 文件来构建聊天机器人的桌面应用程序结构。但是,我不断收到此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/bellacho/opt/anaconda3/lib/python3.7/tkinter/__init__.py", line 1705, in __call__
return self.func(*args)
File "<ipython-input-3-466bf200dfb6>", line 70, in send
res = getResponse(ints, intents)
File "<ipython-input-3-466bf200dfb6>", line 49, in getResponse
tag = ints[0]['intent']
IndexError: list index out of range
知道如何解决这个问题吗?请让我知道,提前谢谢你。 这是我的代码:
def getResponse(ints, intents_json):
tag = ints[0]['intent']
list_of_intents = intents_json['intents']
for i in list_of_intents:
if(i['tag']== tag):
result = random.choice(i['responses'])
break
return result
#Creating tkinter GUI
import tkinter
from tkinter import *
def send():
msg = EntryBox.get("1.0",'end-1c').strip()
EntryBox.delete("0.0",END)
if msg != '':
ChatBox.config(state=NORMAL)
ChatBox.insert(END, "You: " + msg + '\n\n')
ChatBox.config(foreground="#446665", font=("Verdana", 12 ))
ints = predict_class(msg)
res = getResponse(ints, intents)
ChatBox.insert(END, "Bot: " + res + '\n\n')
ChatBox.config(state=DISABLED)
ChatBox.yview(END)
root = Tk()
root.title("Chatbot")
root.geometry("400x500")
root.resizable(width=FALSE, height=FALSE)
【问题讨论】:
-
ints好像是空的 -
predict_class(msg)是做什么的?什么是ints。
标签: python user-interface tkinter