Build A Simple Chat Bot GUI Using Python

Create Your Own Python Chat Bot GUI

Image for post
Image for post

In this article I will show you how to build a graphical user interface (GUI) using the Python programming language that you can use for a chat bot. So no, this won’t be an actual chat bot, I will be focusing on just the graphical user interface components. This is a good exercise to get familiar with creating GUI’s using Python. The graphical user interface (GUI) is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicators such as primary notation, instead of text-based user interfaces, typed command labels or text navigation. -wikipedia

If you are interested in creating a chat bot please check out my other two articles Build Your Own Chat Bot Using Python and Build Your Own Smart AI Chat Bot Using Python & Machine Learning. Also, if you find this article to be useful or helpful, please leave a few claps!

Image for post
Image for post
Build Your Own Smart AI Chat Bot Using Python & Machine Learning
Image for post
Image for post
Build Your Own Chat Bot Using Python

If you prefer not to read this article and would like a video representation of it, you can check out the YouTube Video . It goes through everything in this article with a little more detail and will help make it easy for you to start programming even if you don’t have the programming language Python installed on your computer. Or you can use both as supplementary materials for learning!

Let’s start programming !

Programming

The first thing that I like to do before writing a single line of code is to put in a description in comments of what the code does. This way I can look back on my code and know exactly what it does.

#Description: This is a chat bot GUI

Next I will load the library that I will need to create this GUI.

#Import the library
from tkinter import *

Next I will create the tkinter object. This represents the parent window.

root = Tk()

Now, I will give the Window a title, a shape, and make it such that it can’t be resized.

root.title("Chat Bot")
root.geometry("400x500")
root.resizable(width=FALSE, height=FALSE)

Let’s create the main menu.

main_menu = Menu(root)

Add some sub menus to the main menu.

# Create the submenu 
file_menu = Menu(root)

# Add commands to submenu
file_menu.add_command(label="New..")
file_menu.add_command(label="Save As..")
file_menu.add_command(label="Exit")
main_menu.add_cascade(label="File", menu=file_menu)
#Add the rest of the menu options to the main menu
main_menu.add_command(label="Edit")
main_menu.add_command(label="Quit")
root.config(menu=main_menu)

Create a window for the conversation and place it on the parent window.

chatWindow = Text(root, bd=1, bg="black",  width="50", height="8", font=("Arial", 23), foreground="#00ffff")chatWindow.place(x=6,y=6, height=385, width=370)

Create the text area where the messages will be entered and place it on the parent window.

messageWindow = Text(root, bd=0, bg="black",width="30", height="4", font=("Arial", 23), foreground="#00ffff")
messageWindow.place(x=128, y=400, height=88, width=260)

Create a scroll bar and place it on the parent window.

scrollbar = Scrollbar(root, command=chatWindow.yview, cursor="star")
scrollbar.place(x=375,y=5, height=385)

Create a button to send the message and place it on the parent window.

Button= Button(root, text="Send",  width="12", height=5,
bd=0, bg="#0080ff", activebackground="#00bfff",foreground='#ffffff',font=("Arial", 12))
Button.place(x=6, y=400, height=88)

Run the main loop.

root.mainloop()
Image for post
Image for post

That’s it, we are done creating this program !

If you are also interested in reading more on Python one of the fastest growing programming languages that many companies and computer science departments use then I recommend you check out the book Learning Python written by Mark Lutz’s. Also you can see the full code in this article here.

Image for post
Image for post

Learning Python

Thanks for reading this article I hope it’s helpful to you all! If you enjoyed this article and found it helpful please leave some claps to show your appreciation. Keep up the learning, and if you like Python, machine learning, mathematics, computer science, programming or algorithm analysis, please visit and subscribe to my YouTube channels (randerson112358 & compsci112358 ).

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store