如何在聊天机器人中提供单选按钮作为回复 我尝试了所有可能的解决方案,但没有成功。

问题描述 投票:0回答:1
def radio():
    def sel():
       selection = "You selected the option " + str(var.get())
       label.config(text = selection)


    var = IntVar()
    R1 = Radiobutton(base, text="Option 1", variable=var, value=1,
                      command=sel)
    R1.pack( anchor = W )

    R2 = Radiobutton(base, text="Option 2", variable=var, value=2,
                      command=sel)
    R2.pack( anchor = W )

    R3 = Radiobutton(base, text="Option 3", variable=var, value=3,
                      command=sel)
    R3.pack( anchor = W)

    label = Label(base)
    label.pack() 
    ChatLog.config(state=NORMAL)
    ChatLog.insert(END, "Bot: " + R1 + '\n\n')
    ChatLog.yview(END)`enter code here`



base = Tk()
base.title("POS Chatbot")
base.geometry("400x500")
base.resizable(width=FALSE, height=FALSE)
#Create Chat window
ChatLog = Text(base, bd=0, bg="white", height="8", width="50", font="Arial",)
ChatLog.config(state=DISABLED)
ChatLog.config(foreground="#442265", font=("Verdana", 12 ))
#Bind scrollbar to Chat window
scrollbar = Scrollbar(base, command=ChatLog.yview, cursor="heart")
ChatLog['yscrollcommand'] = scrollbar.set
#Create Button to send message
base.bind('<Return>',call ) 
SendButton = Button(base, font=("Verdana",12,'bold'), text="Send", width="12", height=5,
                    bd=0, bg="#32de97", activebackground="#3c9d9b",fg='#ffffff',
                    command= send )
#Create the box to enter message
EntryBox = Text(base, bd=0, bg="white",width="29", height="5", font="Arial") #Place all components on the screen
scrollbar.place(x=376,y=6, height=386)
ChatLog.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()

单选按钮出现在主窗口中,但没有作为响应。请帮我弄清楚需要做什么才能在聊天机器人中添加按钮类型的响应。下面是我的JSON文件数据集,我正在为这个机器人使用。按钮类型响应的数据集有什么需要修改的吗。请指导我解决这个问题

{
  "intents": [{
      "tag": "greeting",
      "patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day"],
      "responses": ["Hello, thanks for visiting", "Good to see you again", "Hi there, how can I help?"],
      "context_set": ""
    },
    {
      "tag": "thanks",
      "patterns": ["Thanks", "Thank you", "That's helpful"],
      "responses": ["Happy to help!", "Any time!", "My pleasure"]
    },
    {
      "tag": "bye",
      "patterns": ["bye", "good bye", "bubuye"],
      "responses": ["Have a nice day!", "Bye! I helped you", "Bye! Eager to see you again"]
    },
    {
      "tag": "pinpad",
      "patterns": ["I am having issue with the pinpad", "pinpad is not working", "PED is not working", "PP is not working", "issue with PED", "Card transactions are not going on", "pin pad is having issue"],
      "responses": ["please enter the till mac id the pinpad is connected with"]
    },
    {
      "tag": "scale",
      "patterns": ["I am having issue with the scale", "scale is not working", "weigh scale is not working", "weigh check is not working", "issue with scale", "weigh scale is not going on"],
      "responses": ["please enter the till mac id the scale is connected with"]
    },
    {
      "tag": "tasks",
      "patterns": ["What can you do?", "What are your features?", "What are you abilities", "can you sing", "can you talk"],
      "responses": ["I am here to solve POS related technical issue", "Right now i'm in developing stage as soon i'm developed"]
    },

    {
      "tag": "POS",
      "patterns": ["Who are you?", "tell me about yourself", "tell me about you", "what is your name"],
      "responses": ["Hi I'm POS Support and i'm an AI created for solving your technical issue", "POS AI here, a very advance chatbot", "POS AI, chatbot of future"],
      "context_set": ""
    },

    {
      "tag": "creator",
      "patterns": ["Who is your creator?", "who created you", "who is your father", "who is your daddy"],
      "responses": ["I was created by POS Team"],
      "context_set": ""
    }, {
      "tag": "issue",
      "patterns": ["Issue", "I have an issue", "Issue occuring frequently", "not working"],
      "responses": ["Can you please say the issue is in pinpad,scale or scanner?"],
      "context_set": ""
    }
  ]
}
python tkinter radio-button chatbot
1个回答
0
投票

你的代码可能是有效的。我只是改变了发送按钮调用的函数,并添加了两个空函数以防止错误。看看这个。

from tkinter import *


def radio():
    def sel():
       selection = "You selected the option " + str(var.get())
       label.config(text = selection)


    var = IntVar()
    R1 = Radiobutton(base, text="Option 1", variable=var, value=1,
                      command=sel)
    R1.pack( anchor = W )

    R2 = Radiobutton(base, text="Option 2", variable=var, value=2,
                      command=sel)
    R2.pack( anchor = W )

    R3 = Radiobutton(base, text="Option 3", variable=var, value=3,
                      command=sel)
    R3.pack( anchor = W)

    label = Label(base)
    label.pack() 
    ChatLog.config(state=NORMAL)
    ChatLog.insert(END, "Bot: " + R1 + '\n\n')
    ChatLog.yview(END)

def call():
    pass
def send():
    pass

base = Tk()
base.title("POS Chatbot")
base.geometry("400x500")
base.resizable(width=FALSE, height=FALSE)
#Create Chat window
ChatLog = Text(base, bd=0, bg="white", height="8", width="50", font="Arial",)
ChatLog.config(state=DISABLED)
ChatLog.config(foreground="#442265", font=("Verdana", 12 ))
#Bind scrollbar to Chat window
scrollbar = Scrollbar(base, command=ChatLog.yview, cursor="heart")
ChatLog['yscrollcommand'] = scrollbar.set
#Create Button to send message
base.bind('<Return>',call ) 
SendButton = Button(base, font=("Verdana",12,'bold'), text="Send", width="12", height=5,
                    bd=0, bg="#32de97", activebackground="#3c9d9b",fg='#ffffff',
                    command= radio )
#Create the box to enter message
EntryBox = Text(base, bd=0, bg="white",width="29", height="5", font="Arial") #Place all components on the screen
scrollbar.place(x=376,y=6, height=386)
ChatLog.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()

问题很可能出在你的代码中的其他地方。

© www.soinside.com 2019 - 2024. All rights reserved.