A simple Python Learning ChatBot with a Tkinter GUI that stores its knowledge in a JSON file and learns new question-and-answer pairs from user interactions.
- Interactive GUI built with Tkinter
- Knowledge base stored in JSON format
- Fuzzy string matching using Python's
difflib - Learns new question-and-answer pairs from users
- Automatically saves learned answers for future use
- Persistent knowledge base between sessions
- Python 3.8 or higher
- Tkinter (included with most Python installations)
- Clone the repository:
git clone https://github.com/1000red/learning-chatbot-python.git
cd learning-chatbot-python- Install dependencies (optional):
pip install -r requirements.txtNote: This project uses only Python's standard library, so no additional packages are required.
Run the chatbot:
python LearningChatBot.py- Type your question in the input field.
- Press Enter or click Send.
- If the chatbot finds a matching question, it displays the corresponding answer.
- If it doesn't know the answer, it asks you to teach it.
- The new question and answer are automatically saved in
knowledge_base.json. - Type quit to exit the application.
You: What is Python?
Bot: Python is a high-level programming language known for its simplicity and readability.
You: How do I learn programming?
Bot: I don't know the answer. Can you teach me?
User: By practicing regularly and building projects.
Bot: Thank you, I have learned a new answer.
learning-chatbot-python/
├── LearningChatBot.py
└── README.md
- Loads all questions and answers from
knowledge_base.json. - Uses
difflib.get_close_matches()to find the closest matching question. - Returns the corresponding answer if a match is found.
- If no suitable match exists, the chatbot asks the user for the correct answer.
- The new question and answer are saved to the JSON knowledge base for future conversations.
load_knowledge_base()– Loads questions and answers from the JSON file.find_best_match()– Finds the closest matching question.get_answer_for_question()– Retrieves the corresponding answer.save_knowledge_base()– Saves newly learned questions and answers.chat_bot()– Starts the graphical chatbot application.
- Python
- Tkinter
- JSON
- difflib (Fuzzy String Matching)
- Improve question matching accuracy
- Add Natural Language Processing (NLP)
- Store data in a database instead of JSON
- Develop a web-based interface
- Support multiple languages
- Improve the graphical user interface
Contributions are welcome. Feel free to fork the repository and submit a pull request.
This project is provided for educational purposes.
Created as a learning project for Python programming and chatbot development.
If you find a bug or have a suggestion, please open an issue in this repository.