Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I have solved my problem! Thanks @FabienAndre and THISTHIS post. I just realized, that every time i called function, old value of self.photo and self.photo2 variables are cleared and images disappeared.

I have solved my problem! Thanks @FabienAndre and THIS post. I just realized, that every time i called function, old value of self.photo and self.photo2 variables are cleared and images disappeared.

I have solved my problem! Thanks @FabienAndre and THIS post. I just realized, that every time i called function, old value of self.photo and self.photo2 variables are cleared and images disappeared.

Source Link
murzagurskiy
  • 1.3k
  • 1
  • 20
  • 49

I have solved my problem! Thanks @FabienAndre and THIS post. I just realized, that every time i called function, old value of self.photo and self.photo2 variables are cleared and images disappeared.

For solve this trouble, i prepare all images i needed in Class constructor, and every time just use same value in variable.

class Application(tk.Frame):
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.initImages()                                #Prepare images
        self.master.resizable(width=False, height=False)
        self.index = 0
        self.grid()

    def initImages(self):
        self.images = {}
        buf = Image.open("Classic.png")
        buf = buf.resize((20, 20), Image.ANTIALIAS) #The (250, 250) is (height, width)
        self.images['Classic'] = ImageTk.PhotoImage(buf)

        buf = Image.open("Jeopardy.png")
        buf = buf.resize((20, 20), Image.ANTIALIAS) #The (250, 250) is (height, width)
        self.images['Jeopardy'] = ImageTk.PhotoImage(buf)

        buf = Image.open("On-site.png")
        buf = buf.resize((20, 20), Image.ANTIALIAS) #The (250, 250) is (height, width)
        self.images['On-site'] = ImageTk.PhotoImage(buf)

        buf = Image.open("On-line.png")
        buf = buf.resize((20, 20), Image.ANTIALIAS) #The (250, 250) is (height, width)
        self.images['On-line'] = ImageTk.PhotoImage(buf)

    def ShowImages(self, frame_in, type_img, place_img):
        label = tk.Label(frame_in, image=self.images[type_img])
        label.pack(side="right")

        label = tk.Label(frame_in, image=self.images[place_img])
        label.pack(side="right")

    def createWidgets(self, dict_of_data):
        frame = tk.Frame(self, relief='sunken')
        frame.grid(row=0, column=self.index, sticky="WN")
        frame_in = tk.Frame(frame)
        frame_in.grid(row=0, sticky="WE", column=self.index)
        #some other code here

result of solution

P.S. I know, my english is ridiculous, but i have no practice... Sorry