[英]TclError: image “pyimage68” doesn't exist
Had made a tkinter window named Mainpage
of which the snippet is present below:制作了一个名为Mainpage
的 tkinter window,其代码片段如下:
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()
There is no problem in the code whatsoever.代码中没有任何问题。 But, when I import this file to another code an error occurs:但是,当我将此文件导入另一个代码时,会发生错误:
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
A error comes called "pyimage" I have seen the error many times but this time it is strange The TCL error is: "pyimage10" doesn't exist
一个错误叫做“pyimage”我已经多次看到这个错误但这次很奇怪TCL错误是: "pyimage10" doesn't exist
And as edit try it again it changes to "pyimage16" and then it keeps on adding 6 to the no.当编辑再次尝试时,它会更改为“pyimage16”,然后继续将 6 添加到编号中。 beside pyimage...在pyimage旁边...
If you know the solution to this problem I shall be forever grateful.如果你知道这个问题的解决方案,我将永远感激不尽。 I have already tried:我已经尝试过:
As I said, the mainpage file is working normally when I run it but...the problem is in tkinter when I import it to another file.正如我所说,当我运行主页文件时它工作正常但是......当我将它导入另一个文件时,问题出在 tkinter 中。
I got the solution to my problem...if you ever have pyimage error:我得到了我的问题的解决方案......如果你有 pyimage 错误:
Change-改变-
root = tk.Tk()
To-至-
root = tk.Toplevel()
If this does not work, try:如果这不起作用,请尝试:
If your problem is solved an upvote would be appreciated:)如果您的问题得到解决,我们将不胜感激:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.