Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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 如何在聊天机器人中提供单选按钮作为响应我尝试了所有可能的解决方案,但没有成功_Python_Tkinter_Radio Button_Chatbot - Fatal编程技术网

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

Python 如何在聊天机器人中提供单选按钮作为响应我尝试了所有可能的解决方案,但没有成功,python,tkinter,radio-button,chatbot,Python,Tkinter,Radio Button,Chatbot,您的代码可能可以工作。我只更改了使用send按钮调用的函数,并添加了两个空函数以防止出错。看看这个: { "intents": [{ "tag": "greeting", "patterns": ["Hi", "How are you", "Is anyone there?", "Hello", "Good day"], "responses": ["Hello, thanks for visiting", "Good to see you again",

您的代码可能可以工作。我只更改了使用send按钮调用的函数,并添加了两个空函数以防止出错。看看这个:

{
  "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": ""
    }
  ]
}
从tkinter导入*
def收音机():
def sel():
selection=“您选择了选项”+str(var.get())
label.config(text=selection)
var=IntVar()
R1=单选按钮(基本,text=“选项1”,变量=var,值=1,
命令=sel)
R1.包装(锚定=W)
R2=单选按钮(基本,text=“选项2”,变量=var,值=2,
命令=sel)
R2.包(锚=W)
R3=单选按钮(基本,text=“选项3”,变量=var,值=3,
命令=sel)
R3.包装(锚定=W)
标签=标签(基础)
label.pack()
ChatLog.config(状态=正常)
插入(结束,Bot:+R1+'\n\n')
ChatLog.yview(完)
def call():
通过
def send():
通过
base=Tk()
基本标题(“POS聊天机器人”)
基础几何(“400x500”)
可调整大小(宽度=假,高度=假)
#创建聊天窗口
聊天记录=文本(基本,bd=0,bg=“白色”,height=“8”,width=“50”,font=“Arial”,)
ChatLog.config(状态=已禁用)
ChatLog.config(前台=“#442265”,字体=(“Verdana”,12))
#将滚动条绑定到聊天窗口
scrollbar=scrollbar(base,command=ChatLog.yview,cursor=“heart”)
ChatLog['yscrollcommand']=scrollbar.set
#创建按钮发送消息
base.bind(“”,调用)
SendButton=按钮(底部,字体=(“Verdana”,12,'bold'),text=“Send”,width=“12”,height=5,
bd=0,bg=“#32de97”,activebackground=“#3c9d9b”,fg='#ffffff',
命令=无线电)
#创建用于输入消息的框
EntryBox=Text(base,bd=0,bg=“white”,width=“29”,height=“5”,font=“Arial”)#将所有组件放置在屏幕上
滚动条位置(x=376,y=6,高度=386)
聊天记录位置(x=6,y=6,高度=386,宽度=370)
入口盒位置(x=128,y=401,高度=90,宽度=265)
SendButton.place(x=6,y=401,高度=90)
base.mainloop()
问题可能在代码的其他地方

{
  "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": ""
    }
  ]
}
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()