Reputation: 21
Had made a tkinter window named Mainpage
of which the snippet is present below:
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
And as edit try it again it changes to "pyimage16" and then it keeps on adding 6 to the no. beside 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.
Upvotes: 1
Views: 1491
Reputation: 21
I got the solution to my problem...if you ever have pyimage error:
Change-
root = tk.Tk()
To-
root = tk.Toplevel()
If this does not work, try:
If your problem is solved an upvote would be appreciated :)
Upvotes: 1