image - TclError:图像“pyimage68”不存在
问题描述
制作了一个名为的 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 中。
解决方案
我得到了我的问题的解决方案......如果你有 pyimage 错误:
改变-
root = tk.Tk()
至-
root = tk.Toplevel()
如果这不起作用,请尝试:
- 重新启动内核
- 提供图像文件的完整路径
- 提供对图像的引用
如果您的问题得到解决,我们将不胜感激:)
推荐阅读
- reporting-services - SSRS 在一份特定报告上为一位特定用户抛出“无效或过期会话”
- android-emulator - 在 Microsoft 托管代理之间进行通信?
- php - 如何将变量传递给匿名函数?
- sql - 试图将全名解析为 SQL 中的两列
- javascript - React Native - Expo:fontFamily 'SimpleLineIcons' 不是系统字体,尚未通过 Font.loadAsync 加载
- r - 为什么我无法在我的 Rstudio 中安装任何软件包?
- matlab - Matlab编码相关的两个问题
- sonos - getfavorites API 调用未返回的节目
- android - 如何在 Android Intent 上检索 content:// 的绝对路径?
- c# - 错误 CS8107:功能“元组相等”在 C# 7.0 中不可用。请使用语言版本 7.3 或更高版本