CODE :
from tkinter import *
# Create main window
window = Tk()
window.title("Healthcare Chatbot")
window.geometry('600x600')
window.configure(bg='#0084ff')
# Chat log area
chat_log = Text(window, height=23, width=65, bg='#f5f5f5', font=('Helvetica', 12))
chat_log.place(x=10, y=10)
# Scrollbar
scrollbar = Scrollbar(window)
scrollbar.place(x=590, y=10, height=420)
chat_log.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=chat_log.yview)
# Entry field with reduced width (shorter)
input_field = Entry(window, width=42, font=('Helvetica', 14))
input_field.place(x=10, y=510, height=35)
# Send button placed next to the input field, fixed position (not docked)
send_button = Button(window, text="Send", font=('Helvetica', 14), command=lambda: send_message())
send_button.place(x=500, y=507)
# Function to get chatbot response
def get_chatbot_response(user_input):
user_input = user_input.lower()
if "hello" in user_input:
return "Hello! How can I assist you?"
elif "how are you" in user_input:
return "I'm just a bot, but I'm doing great! How about you?"
elif "symptoms" in user_input:
return "Please describe your symptoms in more detail."
elif "headache" in user_input:
return "It could be a migraine or tension headache. Consider taking a pain reliever and resting."
elif "fever" in user_input:
return "A fever could indicate an infection. Monitor your temperature and consult a doctor if it persists."
elif "cold" in user_input:
return "Rest, stay warm, and drink plenty of fluids. Over-the-counter cold remedies may help relieve symptoms."
elif "cough" in user_input:
return "A cough can be caused by many things. Try warm fluids and cough syrup. If it persists, see a doctor."
elif "stomach pain" in user_input or "abdominal pain" in user_input:
return "Stomach pain can have many causes like indigestion or infection. If it's severe or ongoing, seek medical advice."
elif "diabetes" in user_input:
return "Diabetes requires careful management of blood sugar levels through diet, medication, and exercise."
elif "blood pressure" in user_input or "hypertension" in user_input:
return "High blood pressure should be monitored regularly. A healthy lifestyle and medication can help control it."
elif "covid" in user_input or "coronavirus" in user_input:
return "COVID-19 symptoms include fever, cough, and loss of taste/smell. Isolate and get tested if you suspect infection."
elif "allergy" in user_input:
return "Allergies can cause sneezing, rashes, or itching. Avoid triggers and consider antihistamines."
elif "sore throat" in user_input:
return "Try warm saltwater gargles and stay hydrated. If the sore throat persists, consult a healthcare provider."
elif "chest pain" in user_input:
return "Chest pain could be serious. If it's severe, radiates, or comes with shortness of breath, seek emergency help."
elif "vomiting" in user_input:
return "Stay hydrated and rest. If vomiting persists or is severe, consult a doctor."
elif "diarrhea" in user_input:
return "Drink plenty of fluids to stay hydrated. Avoid spicy food. If it continues, seek medical advice."
elif "back pain" in user_input:
return "Try rest, gentle stretches, and applying heat. If pain is chronic or severe, consult a doctor."
elif "rash" in user_input or "skin" in user_input:
return "Skin rashes can be due to allergies or infections. Keep the area clean and avoid irritants."
elif "asthma" in user_input:
return "Use your inhaler as prescribed and avoid triggers like smoke and dust. Seek help if breathing worsens."
elif "depression" in user_input:
return "I'm sorry you're feeling this way. Consider talking to a mental health professional for support."
elif "anxiety" in user_input:
return "Try to relax and breathe deeply. If anxiety is affecting daily life, speak to a mental health professional."
elif "urination" in user_input or "pee" in user_input or "urinary" in user_input:
return "Painful or frequent urination can indicate a UTI. Drink water and consult a doctor if it persists."
elif "eye pain" in user_input or "eyes" in user_input:
return "Eye pain can be caused by strain, infection, or injury. Avoid screens and see a specialist if needed."
else:
return "I'm sorry, I don't have information on that. Can you be more specific?"
# Function to send message
def send_message():
user_input = input_field.get()
if user_input.strip() == "":
return
chat_log.insert(END, "You: " + user_input + "\n")
input_field.delete(0, END)
response = get_chatbot_response(user_input)
chat_log.insert(END, "Chatbot: " + response + "\n\n")
chat_log.see(END)
# Bind Enter key to send message
window.bind('<Return>', lambda event: send_message())
# Run the main loop
window.mainloop()