如何解决 tkinter 中不存在图像“pyimage16”

问题描述 投票:0回答:0

任何人都可以建议如何摆脱我在尝试将背景图像添加到 tkinter 窗口时收到的以下错误消息。我已经尝试了所有可能的方法,但仍然没有运气。另外,是否可以在 tkinter 的输出窗口中提供屏幕截图,我们该怎么做?

下面是我的代码:

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()

错误信息:

python tkinter tkinter-canvas tkinter-entry tkinter-button
© www.soinside.com 2019 - 2024. All rights reserved.