Healthcare Chatbot Using Tkinter GUI in Python
PROGRAM:
from tkinter import *
from PIL import Image, ImageTk
window = Tk()
window.title(" Welcome To Shrinidhi Healthcare Chatbot")
window.geometry('600x600')
window.resizable(False, False)
bg_image = Image.open(r"C:\\Users\\shrin\\Downloads\\Lovepik_com-401764710-hospital-background.jpg")
bg_image = bg_image.resize((600, 600), Image.Resampling.LANCZOS)
bg_photo = ImageTk.PhotoImage(bg_image)
canvas = Canvas(window, width=600, height=600)
canvas.pack(fill="both", expand=True)
canvas.create_image(0, 0, image=bg_photo, anchor="nw")
messages = []
def get_chatbot_response(user_input):
user_input = user_input.lower()
if "hello" in user_input:
return "How can I assist you?"
elif "fever" in user_input:
return "It may be due to climate change."
elif "headache" in user_input:
return "It might be a migraine or due to mobile usage."
elif "typhoid" in user_input:
return "Typhoid spreads through contaminated water and food."
elif "malaria" in user_input:
return "Malaria is caused by mosquitoes."
elif"cancer"in user_input:
return"It Is Due To Uncontrolled Growth Of Cells"
elif "diabetes"in user_input:
return"A condition where the body struggles to regulate blood sugar"
elif "bp" in user_input:
return"A condition that increases heart risks"
elif "asthma"in user_input:
return"A lung condition making difficult"
else:
return "I'm sorry, I can't understand that."
def draw_messages():
canvas.delete("text")
y = 20
for msg in messages:
canvas.create_text(10, y, anchor="nw", text=msg, font=("Arial", 12), fill="black", width=580, tags="text")
y += 30
def send_message():
user_text = input_field.get()
if user_text.strip() == "":
return
messages.append("You: " + user_text)
response = get_chatbot_response(user_text)
messages.append("Chatbot: " + response)
input_field.delete(0, END)
draw_messages()
input_field = Entry(window, font=("Arial", 14), width=45)
input_field.place(x=10, y=550)
send_button = Button(window, text="Send", font=("Helvetica", 12), command=send_message, bg="#4CAF50", fg="white")
send_button.place(x=480, y=545)
window.mainloop()
OUTPUT:
Comments
Post a Comment