Can anyone pls suggest how to get rid of the following error msg i am getting while trying to add background image to tkinter window. i have tried every possible thing i could but still no luck.Also, is it possbile to provide screenshot in output window of tkinter, how can we do that ?
Below is my code :
from tkinter import *
from PIL import ImageTk, Image
import webbrowser
from tkinter import scrolledtext
# Create the main window
root = tk.Tk()
# Set the title of the window
root.title("Chatbot")
image_0=Image.open("C:\\Users\\ankit\\Desktop\\Deloitte.png")
back_end=ImageTk.PhotoImage(image_0)
root.geometry('800x600')
lbl=Label(root,image=back_end)
lbl.place(x=0,y=0,relwidth=1,relheight=1)
# Function to open a website
def open_website(url):
webbrowser.open(url)
# Function to handle user input and generate bot response
def get_bot_response():
user_input = input_box.get("1.0", tk.END).strip()
output_box.configure(state='normal') # Enable editing the output box
output_box.insert(tk.END, 'User: {}\n'.format(user_input))
# Check user queries and provide instructions accordingly
if 'book a seat' in user_input:
instructions = "To book a seat, please follow these steps:\n\n"
instructions += "1. Visit our seat booking portal: [Seat Booking Portal Link]\n"
instructions += "2. Log in with your credentials or create a new account if you haven't already.\n"
instructions += "3. Select the desired date and time for your booking.\n"
instructions += "4. Choose the type of seat you want (e.g., window seat, aisle seat, etc.).\n"
instructions += "5. Confirm your selection and proceed to payment.\n"
instructions += "6. Once the payment is completed, you will receive a confirmation email with the seat details.\n"
instructions += "7. Arrive at the designated location at least 15 minutes before the scheduled departure time.\n"
instructions += "8. Enjoy your journey!\n\n"
instructions += "Screenshot:\n"
instructions += "[Screenshot of Seat Booking Process]"
output_box.insert(tk.END, 'Bot: {}\n'.format(instructions))
output_box.see(tk.END) # Scrolls the output box to show the latest message
else:
response = "Sorry, I need to get trained on this topic. I'll note it down for future training. Can I assist you with something else?"
output_box.insert(tk.END, 'Bot: {}\n'.format(response))
output_box.see(tk.END) # Scrolls the output box to show the latest message
output_box.configure(state='disabled') # Disable editing the output box
# Button to open HR portal
hr_button = tk.Button(root, text="Open HR Portal", command=lambda: open_website("https://www.hrportal.com"))
hr_button.pack()
# Label for Input Box
input_label = tk.Label(root, text="User Input:")
input_label.pack()
# Input Box
input_box = scrolledtext.ScrolledText(root, height=5, width=50)
input_box.pack()
# Label for Output Box
output_label = tk.Label(root, text="Bot Response:")
output_label.pack()
# Output Box
output_box = scrolledtext.ScrolledText(root, height=15, width=50)
output_box.pack()
# Send Button
send_button = tk.Button(root, text="Send", command=get_bot_response)
send_button.pack()
# Run the main loop
root.mainloop()