制作了一个名为的 tkinter 窗口Mainpage
,其中的片段如下所示:
def mainpage():
import tkinter as tk
from PIL import ImageTk, Image
root = tk.Tk()
image=Image.open("logo2.png")
photo = ImageTk.PhotoImage(image)
lab = tk.Label(root, image=photo, bd=0, highlightthickness=0) # <----Error is coming for this line in the next code
lab.image=photo
lab.place(x=460,y=245)
button = tk.Button(root, text="Search",font="CenturyGothic",fg="Darkred",width="70",
height="24",command=veryuseful)
img1 = ImageTk.PhotoImage(file="gold.png")
button.config(image=img1,compound="center")
button.place(x=850,y=340)
root.mainloop()
代码中没有任何问题。但是,当我将此文件导入另一个代码时,会发生错误:
import Mainpage # <----imported the file here
condition=0
for i in d:
if i[3]==username:
if i[4]==password:
head=tk.Label(win, text="Welcome to Library X",fg="Light blue",bg="Black" ,font=("Arial",12))
head.grid(column=1, row=7)
condition=1
break
else:
messagebox.showerror("ERROR", "Wrong Password!")
condition=2
break
else:
continue
condition=0
if condition==0:
messagebox.showerror("ERROR", "Wrong Username!")
if condition==1:
Mainpage.mainpage() # <------Used the function mainpage from file
一个名为“pyimage”的错误我已经多次看到该错误但这次很奇怪TCL错误是:"pyimage10" doesn't exist
当编辑再次尝试时,它会更改为“pyimage16”,然后继续将 6 添加到编号中。在pyimage旁边...
如果你知道这个问题的解决方案,我将永远感激不尽。我已经尝试过:
- 提供文件的完整路径
- 使用了对图像的引用
- 重新启动内核
正如我所说,当我运行它时,主页文件正常工作,但是......当我将它导入另一个文件时,问题出在 tkinter 中。