1

I'm trying to call a String from a entry box in another class to a public Var. The code for calling the Var seams to work fine but got a Error ''' image "pyimage5" doesn't exist''' on my second class sins i added the new lines of code. Everything was working fun before.

Lines of code I added:

class StartPage(tk.Frame):

     def __init__(self, parent, controller):
         tk.Frame.__init__(self,parent)

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent,bg=Gray_Back_Page_1)

to

class StartPage(tk.Frame):

     def __init__(self, parent, controller):
         super(StartPage,self).__init__()

class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        super(PageOne,self).__init__(parent,bg=Gray_Back_Page_1)

and added the following code outside a class

StartPage_object = StartPage(tk.Frame, SeaofBTCapp) 
USER = StartPage_object.Username_Text.get() 
PASSWORD = StartPage_object.Password_Text.get()

The image code Var = Image.open(Image_File +"\File_Name.png") seams to work in my Start Page but gives me an Error in my Page One

Please see complete code below:

desktop = os.path.expanduser("~\Desktop")
Image_File = os.path.expanduser("~\Desktop\file")

#===============Frame==========================Container====================>
class SeaofBTCapp(tk.Tk,object):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs)
        tk.Tk.wm_title(self, "Name")
        tk.Tk.geometry(self,"1360x728")
        tk.Tk.iconbitmap(self, default= desktop + "\icon.ico")
        self.resizable(False, False)
        #tk.Tk.overrideredirect(False)

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand = True)
        container.grid_rowconfigure(0, weight=10)
        container.grid_columnconfigure(0, weight=10)

        self.frames = {}

        for F in (StartPage, PageOne):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):

        frame = self.frames[cont]
        frame.tkraise()

#===============Start=========================Page====================>
class StartPage(tk.Frame):

     def __init__(self, parent, controller):
         super(StartPage,self).__init__()

     #=============Set_Background==================>
     load1 = Image.open(Image_File +"\Login_Bcakground.png")
     render1 =ImageTk.PhotoImage(load1)

     #========= Reset_username & Password ===========>
     self.Username_Text= tk.StringVar()
     self.Password_Text= tk.StringVar()

     #==== Creating Buttons, Entry Box and Labels with there commands =====>
     User_Name_Entry = tk.Entry(self,textvariable = self.Username_Text, fg = 
                        Entry_Box_Text_Colour,bg = 
                        Entry_Box_Back_White,borderwidth = 0, 
                        font=Normal_Text,width = 30)
     User_Name_Entry.place(x=795,y=282)

     User_Pass_Entry = tk.Entry(self,textvariable = selfPassword_Text, fg = 
                       Entry_Box_Text_Colour,bg = 
                       Entry_Box_Back_White,borderwidth = 0, 
                       font=Normal_Text,width = 30)
     User_Pass_Entry.place(x=795,y=329)

#===============Login==========================Var====================>

StartPage_object = StartPage(tk.Frame, SeaofBTCapp) 
USER = StartPage_object.Username_Text.get() 
PASSWORD = StartPage_object.Password_Text.get()

#===============Page==========================One====================>
class PageOne(tk.Frame):

    def __init__(self, parent, controller):
        super(PageOne,self).__init__(parent,bg=Gray_Back_Page_1)

        photo = ImageTk.PhotoImage(Image.open(Image_File +"\Splach_Page.png"))      
        vlabel=tk.Label(self,text = "",image=photo)
        vlabel.image = photo
        vlabel.place (x=-1,y=-5,relwidth=1, relheight=1)

Error Lines:

image "pyimage5" doesn't exist
Stack trace:
 >  File "C:\Users\MainUser\source\v_1_1.py", line 251, in __init__
 >    vlabel=tk.Label(self,text = "",image=photo)
 >  File "C:\Users\MainUser\source\v_1_1.py", line 93, in __init__
 >    frame = F(container, self)
 >  File "C:\Users\MainUser\source\v_1_1.py", line 2736, in <module>
 >    app = SeaofBTCapp()
Loaded '__main__'

3 Answers 3

1

for me, the problem was with Spyder not the code. I changed to Jupyter Notebook and it worked as expected

Sign up to request clarification or add additional context in comments.

Comments

0

This looks like a known bug in tkinter, where the python garbage collector deletes the photo. To prevent this, you need to create a global reference to the image. Something like this should work:

class PageOne(tk.Frame):
    images = []

    def __init__(self, parent, controller):
        super(PageOne,self).__init__(parent,bg=Gray_Back_Page_1)

        photo = ImageTk.PhotoImage(Image.open(Image_File +"\Splach_Page.png"))
        PageOne.images.append(photo)     
        vlabel=tk.Label(self,text = "",image=photo)
        vlabel.image = photo
        vlabel.place (x=-1,y=-5,relwidth=1, relheight=1)

Hope that works for you!

2 Comments

This did not work and give me the same error, but your idea helped me to solve it in another way. I went back to my original code and solved my first issue with the list methods. Thank you.
Please post your solution as an answer to help others with the same problem.
0

This did not work and give me the same error, but your idea helped me to solve it in another way. I went back to my original code and solved my first issue with the list methods.

#=============Use_List_For_Capturing_Var_In_Classes==================

Name_oF_User_Loged_In = []
Name_oF_User_Loged_In.append("User Name")

class StartPage(tk.Frame):

   global login_data_Pass
   global login_data_User
   global Name_oF_User_Loged_In

   def __init__(self, parent, controller):
        tk.Frame.__init__(self,parent)
   #=============Set_Background==================>
   load1 = Image.open(Image_File +"\Login_Bcakground.png")
   render1 =ImageTk.PhotoImage(load1)

   def Login_Check():
                USER1 = self.Username_Text.get()
                PASSWORD1 = self.Password_Text.get()
                login_data_Pass.pop(0)
                login_data_User.pop(0)
                login_data_Pass.append(PASSWORD1)
                login_data_User.append(USER1) 

   #==== Creating Buttons, Entry Box and Labels with there commands =====>

   Login_button = tk.Button(self, text="Login", 
           fg="#d0cece",bg="#3f9a84",borderwidth = 0, font=Normal_Text,height 
           =1,width = 10,
           command=lambda: Login_Check())
   Login_button.place(x=1010,y=380)

   User_Name_Entry = tk.Entry(self,textvariable = self.Username_Text, fg = 
                    Entry_Box_Text_Colour,bg = 
                    Entry_Box_Back_White,borderwidth = 0, 
                    font=Normal_Text,width = 30)
   User_Name_Entry.place(x=795,y=282)

   User_Pass_Entry = tk.Entry(self,textvariable = selfPassword_Text, fg = 
                   Entry_Box_Text_Colour,bg = 
                   Entry_Box_Back_White,borderwidth = 0, 
                   font=Normal_Text,width = 30)
   User_Pass_Entry.place(x=795,y=329)


class PageOne(tk.Frame):

  global login_data_Pass
  global login_data_User
  global Name_oF_User_Loged_In

  def __init__(self, parent, controller):
      tk.Frame.__init__(self, parent,bg=Gray_Back_Page_1)

         photo = ImageTk.PhotoImage(Image.open(Image_File +"\Splach_Page.png"))      
         vlabel=tk.Label(self,text = "",image=photo)
         vlabel.image = photo
         vlabel.place (x=-1,y=-5,relwidth=1, relheight=1)

         user = login_data_User[0]
         password = login_data_Pass[0]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.