A chatbot is an artificial intelligence (AI) software that can simulate a conversation (or a chat) with a user in natural language.

Many websites and applications now days have embedded chatbot on them to help improve customer experience

On this tutorial you’re going to learn how to build your own simple chatbot using Python Programming .


Don’t worry if you never had any experience with AI or Machine Learning since our python chatbot that we are about to build just use normal logic.


If you’re in window you don’t need to install anything because every module we are going to use comes automatic with Python Standard Library

However if you’re Linux user you might need to Install Tkinter Libary on your own


$ pip install python-tk 

Also you need to have Dictionary json on your local folder which will act as our Knowledge base for our chatbot .

Download the Below Json Dictionary and put it on your project Directory

knowledge Json Download

Project Directory

Your project directory should look as shown below

├── app.py
└── knowledge.json
0 directories, 2 files

Building Our Chatbot

Now after you have set everything clear let’s start building our application.

Throughout the project we are going to use the following Python standard modules

Importing Modules

Now import all necessary modules ready to start crafting our chatbot

import json
from difflib import get_close_matches
from tkinter import Tk, Label, Entry, Button, Text, Scrollbar,Frame

Create app cover for our python chatbot

We now required to create the exoskeleton of our application by designing our User Interface for our chatbot using tkinter Library.

Our chatbot UI will need to have the following features

  • Entry box to allow as to type a message
  • A button to submit the message
  • Message part for showing the conversation with chatbot
  • Scroll bar to help us scroll throughout the conversation

Using knowledge of tkinter I have crafted the above features into Python code shown below.

#projects #chatbot #nlp #tkinter #python

Build your own simple conversational chatbot in Python in just few lines of code
32.05 GEEK