Updating a Label picture (Tk) in Python 3, has strange results
Updating a Label picture (Tk) in Python 3, has strange results
Good evening,
I am requesting your assistance about a strange behavior with Python 3 (Tk Library).
The idea was to bind a Mouse Enter event with arguments, to a Label object containing a picture (Label Object name is : 「panel」).
The method only had to update the picture.
*The arguments contains four variables, we don't care about i and j yet, I just need the Image object ready to be processed, and the panel (Label) to have it's picture updated (in my example, I just use rotate method).
The function does it job, however the picture becomes blank when the panel (Label) gets updated for some reason and this is what I cannot understand !
I am still a newbie with this library and Python overall, so it may be a tiny mistake, or I'm just totally wrong with the conception, I would be happy if someone had any clue!
Allow me to share the portion of code concerned :
【images】is an array that have PhotoImage objects
【chunks】is an array that have Image objects (in order to use rotate function below...).
def draw(self):
# Drawing to Grid and Binding
iCurr = 0
for i in range(self.iPanelAmount):
for j in range(self.iPanelAmount):
panel = Label(self.master, image = self.images[iCurr], cursor="tcross")
panel.grid(column=j, row=i)
panel.bind('<Enter>', lambda event, arg=(i, j, self.chunks[iCurr], panel): self.mouseOver(arg))
iCurr += 1
# End Loop [J]
# End Loop
def mouseOver(self, arg):
chunk = arg[2]
panel = arg[3]
chunk.rotate(90)
updated_image = ImageTk.PhotoImage(chunk)
panel.configure(image = updated_image)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Comments
Post a Comment