I tried to outputting images in label. There are two images, which need to appear in labels several times. And they have appeared only once - in the latter labels.
class Application(tk.Frame):
def __init__(self, master=None):
#some actions
def ShowImages(self, frame_in, type_img, place_img):
print type_img
print place_img
print frame_in
self.image = Image.open(type_img + ".png")
self.image = self.image.resize((20, 20), Image.ANTIALIAS) #The (250, 250) is (height, width)
self.photo = ImageTk.PhotoImage(self.image)
label = tk.Label(frame_in, image=self.photo, relief='sunken', borderwidth=2)
label.pack(side="right")
self.image2 = Image.open(place_img + ".png")
self.image2 = self.image2.resize((20, 20), Image.ANTIALIAS) #The (250, 250) is (height, width)
self.photo2 = ImageTk.PhotoImage(self.image2)
label = tk.Label(frame_in, image=self.photo2, relief='sunken', borderwidth=2)
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)
header = tk.Label(frame_in, anchor="nw", justify="left", text="Игра: ")
header.pack(expand=True, fill="x", side="left")
self.ShowImages(frame_in, dict_of_data["type"], dict_of_data["place_type"])
#some other code
if __name__ == "__main__":
app = Application()
app.master.title('Sample application')
#All that data is not real data of my script
app.createWidgets({'name':"", 'state':"", "type":"", "date":{"start":"", 'end':""}, 'duration':{'days':'', 'hours':''}, 'site':'', 'rank':''})
app.createWidgets({'name':"", 'state':"", "type":"", "date":{"start":"", 'end':""}, 'duration':{'days':'', 'hours':''}, 'site':'', 'rank':''})
app.createWidgets({'name':"", 'state':"", "type":"", "date":{"start":"", 'end':""}, 'duration':{'days':'', 'hours':''}, 'site':'', 'rank':''})
app.mainloop()
So, in two words: I tried to invoke function ShowImages three times, and i want to see 6 images (3 x 2 images), but i see only the last 2. Names of images are identical.
I think this is trouble with opening images. Maybe there is some rule, how i can use one image several times.
P. S. Sorry for my english. I didn't know, how i need to describe my trouble. Thanks.