Python Chatbot.after()没有函数吗?

Python Chatbot.after()没有函数吗?,python,function,tkinter,chatbot,Python,Function,Tkinter,Chatbot,我正在制作一个聊天机器人,我知道了如何根据用户的输入发送一个机器人响应,但是我想在机器人消息发送之前等待2秒钟。为了使用.after()方法实现这一点,我需要调用一个函数。我最初尝试了一个嵌套函数,但没有成功 我不能调用send()函数,因为这是将用户输入发送到主对话(文本小部件)的方法,我不希望每次发送都需要2秒钟 有效的当前代码: # gets message from user and sends to main chatroom def send(self): the_mess

我正在制作一个聊天机器人,我知道了如何根据用户的输入发送一个机器人响应,但是我想在机器人消息发送之前等待2秒钟。为了使用.after()方法实现这一点,我需要调用一个函数。我最初尝试了一个嵌套函数,但没有成功

我不能调用send()函数,因为这是将用户输入发送到主对话(文本小部件)的方法,我不希望每次发送都需要2秒钟

有效的当前代码:

# gets message from user and sends to main chatroom 
def send(self):
    the_message = self.user.get()
    assign_user = '\n' 'You: ' + the_message
    self.chatroom.insert('end', assign_user, 'you')

    **# I need to be able to call the following if statement by a function name (to use the .after() method), but I need the previous lines of code to detect when a user sends something and what they said in the first place**
    if the_message != '' and '?' in the_message:
        bot_message = '\n' 'Sam: Thanks for your question(s)! Please type your email and I will get back to you ASAP.'
        self.chatroom.insert('end', bot_message, 'sam')
    elif the_message != '' and '?' not in the_message:
        bot_message = '\n' 'Sam: Thanks for your message! Please type your email and I will get back to you ASAP.'
        self.chatroom.insert('end', bot_message, 'sam')    

如果您想让我们帮助您使代码正常工作,我们需要查看不起作用的代码,而不是无法正常工作的代码。无论您在何处调用
self.send()
,在获得用户输入后,请调用
xxx.after(2000,self.send)
,其中
xxx
是任何小部件或根窗口。