I am trying to build a simple chat bot where it will provide users with a guide on where or how to get support for different systems.
My idea is to have an initial drop down where they can select which system they are having an issue on whether that be a corporate, cloud, etc.
then a second drop down would be filtered based on the first drop down, which would contains application options within the system chosen from the first drop down.
This would be similar to car websites where you could select the brand and then it filters the models and letes you select a model.
This would then give the users a 3rd drop down with typical quieries with the chosen application.
I want it to just be buttons for the users so its quick and simple.
I have created a simple GUI, I can do just a user types in text and it spits out an answer but I want to reduce what the users have to type so it doesnโt fail due to spelling errors.
I am user combobox but that brings up a popup menu that tends to hide behind the application, I want to try have it where its just integrated into the GUI. Making it easier for the user to adjust the filters if needed quickly
Edit: I forgot to include the code:
from tkinter import *
import tkinter as tk
from tkinter import PhotoImage
from tkinter import Label, Tk
from PIL import Image, ImageTk
import datetime
# greetings based on time opening chatbot
current_time = datetime.datetime.now()
if 6 <= current_time.hour <= 12:
greeting = "Good Morning!"
elif 12 <= current_time.hour <= 16:
greeting = "Good Afternoon!"
else:
greeting = "Good Evening!"
# Tkinter UI/UX design
root=Tk()
root.title('Systems Chatbot')
root.geometry('720x400+150+100')
root.configure(bg='light blue')
root.resizable(False, False)
# Heading label to inform the user what to do
heading = Label(root, text=f"{greeting} ๐. I'm the Systems Chatbot. I have Systems answers for you from the drop-down menu.", fg='#000', bg='white', font=('Microsoft YaHei UI Light', 10, 'bold'))
heading.place(x=10, y=5)
desktop_systems = ["Corporate", "Access", "Core"]
system_options = ["Edge", "Office"], ["Excel", "Network"], ["Control", "PDF"]
root = tk.Tk()
tkvar = tk.StringVar(root)
tkvar.set("Select a System") # set the default option
tkvar2 = tk.StringVar(root)
tkvar2.set("Select a System Option") # set the default option
popupMenu1 = tk.OptionMenu(root, tkvar, *desktop_systems)
popupMenu1.pack()
popupMenu2 = tk.OptionMenu(root, tkvar2, [])
popupMenu2.pack()
def change_dropdown(*args):
print("Chosen brand " + tkvar.get())
for i in range(len(desktop_systems)):
if tkvar.get() == desktop_systems[i]:
popupMenu2["menu"].delete(0, "end")
for item in system_options[i]:
popupMenu2['menu'].add_command(label=item, command=tk._setit(tkvar2, item))
root.mainloop()
From this, you can try a script like this (modify it as needed):
import tkinter as tk
class TestMenuApp(tk.Tk):
def __init__(self):
super().__init__()
top_menu = tk.Menu(self) # Create the top menu root
self.config(menu=top_menu) # Enable display of menu on window
file_menu1 = tk.Menu(top_menu, tearoff=0) # Create the menu handle
top_menu.add_cascade(label="File", menu=file_menu1) # Create 'File' main menu option
file_menu1.add_command(label="New file", command=self.print)
file_menu1.add_command(label="Open", command=self.open)
file_menu1.add_separator()
# Create sub-menus for the Save 'File' menu option
save_sub_menu = tk.Menu(file_menu1, tearoff=0)
file_menu1.add_cascade(label="Save", menu=save_sub_menu)
save_sub_menu.add_command(label='local drive')
save_sub_menu.add_command(label='external drive')
# Create sub-menus for the printing 'File' menu option
print_sub_menu = tk.Menu(file_menu1, tearoff=0)
file_menu1.add_cascade(label="Printing", menu=print_sub_menu)
print_sub_menu.add_command(label='Laser printer')
print_sub_menu.add_command(label='Standard printer')
# Other top menu options
top_menu.add_command(label="About", command=self.about)
top_menu.add_command(label="Quit", command=self.destroy)
self.config(menu=top_menu)
@staticmethod
def print():
print('\nHello, I am from the New File menu option.')
@staticmethod
def open():
print('\nI am from the Open menu option.')
@staticmethod
def about():
print('\nThis is a simple drop-down menu script for testing purposes.')
if __name__ == "__main__":
app = TestMenuApp()
app.mainloop()
If you run this script, you will see that there are three main menu options: File, About, and Quit. Only the File option is expanded for demo purposes. About, if selected, prints a message to the screen. If Quit is selected, the program exits. Note that these two actions are facilitated by the methods following the command assignment options for each sub-menu definition.
The File main menu option contains four sub-menu options: New File, Open, Save, and Printing. The first two options, when selected, print a message to the screen. The last two each contain a sub-menu of their own. The last two options, namely Save and Printing appear to be similar to what you are looking for. Note that I have added more options to generalize it.
from tkinter import *
import tkinter as tk
from tkinter import Label, Tk
import datetime
# greetings based on time opening chatbot
current_time = datetime.datetime.now()
if 6 <= current_time.hour <= 12:
greeting = "Good Morning!"
elif 12 <= current_time.hour <= 16:
greeting = "Good Afternoon!"
else:
greeting = "Good Evening!"
# Tkinter UI/UX design
root = Tk()
root.title("Systems Chatbot")
root.geometry("1240x400+150+100")
root.configure(bg="light blue")
root.resizable(False, False)
# Heading label to inform the user what to do
heading = Label(
root,
text=f"{greeting} ๐. I'm the Systems Chatbot. I have Systems answers for you from the drop-down menu.",
fg="#000",
bg="white",
font=("Microsoft YaHei UI Light", 10, "bold"),
)
heading.place(x=10, y=5)
desktop_systems = ["Corporate", "Access", "Core"]
system_options = {
"corporate": ["Edge", "Office"],
"access": ["Excel", "Network"],
"core": ["Control", "PDF"],
}
tkvar = tk.StringVar(root)
tkvar.set("Select a System") # set the default option
tkvar2 = tk.StringVar(root)
tkvar2.set("Select a System Option") # set the default option
def change_dropdown(event):
# Obtain the system's name.
selected_system = tkvar.get().lower()
# Clear the selection.
tkvar2.set("Select a System Option")
# Assign new set of options.
if selected_system in system_options.keys():
popupMenu2["menu"].delete(0, "end")
for item in system_options[selected_system]:
popupMenu2["menu"].add_command(label=item, command=tk._setit(tkvar2, item))
popupMenu1 = tk.OptionMenu(root, tkvar, *desktop_systems, command=change_dropdown)
popupMenu1.pack(side=LEFT)
popupMenu2 = tk.OptionMenu(root, tkvar2, [])
popupMenu2.pack(side=LEFT)
root.mainloop()
You were close, you was probably looking for the article in the second link.