0

我目前正在做一个有主页和菜单栏的项目。在菜单栏中,当做出选择时,它应该打开另一个 GUI。但是,我收到一个错误,如图所示。

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\****\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "C:\Users\****\Desktop\******\******\***\******\Homepage.py", line 41, in MSC_01
    my_label = Label(root, image=bg)
  File "C:\Users\****\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 2766, in __init__
    Widget.__init__(self, master, 'label', cnf, kw)
  File "C:\Users\****\AppData\Local\Programs\Thonny\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: image "pyimage2" doesn't exist

我想知道是否有人可以在这里帮助我,因为我不知道为什么会这样。下面附上我的代码。

import csv,random,time,os
from itertools import count
import pandas as pd
import numpy as np
import tkinter as tk
from tkinter import*
from PIL import ImageTk, Image

root = Tk()
root.title('LV Condition Monitoring')
root.geometry("1000x980")

#define image
bg1 = PhotoImage(file="C:/Users/****/Desktop/******/******/****/******.png")

my_label1 = Label(root, image=bg1)
my_label1.place(x=0, y=0, relwidth=1, relheight=1)

my_text1 = Label(root, text="Low Voltage Condition Monitoring", font=("Arial",20), fg="black")
my_text1.pack(pady=50)
    
my_menu = Menu(root)
root.configure(menu=my_menu)

def MSC_01():
    *tkinter GUI code*

#Create menu item
open_menu = Menu(my_menu)
my_menu.add_cascade(label="Open", menu=open_menu)
open_menu.add_command(label="MSC 01", command=MSC_01)

root.mainloop()
4

0 回答 0