Skip to content
Permalink
master
Go to file
 
 
Cannot retrieve contributors at this time
28 lines (23 sloc) 693 Bytes
import random
import tkinter as tk
root = tk.Tk()
userInput = tk.Entry(root)
userInput.pack()
greetings = ['hola', 'hello', 'hi', 'hey!', 'hey']
question = ['how are you?', 'how are you doing?', 'how are you', 'how are you doing']
responses = ['Okay', "I'm fine"]
huh = "I did not understand what you said"
def cb(event):
userText = userInput.get()
userText = userText.lower()
if userText in greetings:
botText = random.choice(greetings)
elif userText in question:
botText = random.choice(responses)
else:
botText = huh
output.config(text=botText)
userInput.bind("<Return>", cb)
output = tk.Label(root, text='')
output.pack()
tk.mainloop()
You can’t perform that action at this time.