Allow Image update to set size

Previously, updating an Image element with a new size would change the element size, possibly disrupting the GUI layout. Sometimes using a specified / fixed image size is preferred. This patch allows an optional size argument to the Update method.
This commit is contained in:
Ricardo Mendonça Ferreira 2018-11-02 16:53:52 -03:00 committed by GitHub
parent 1c7a6d263d
commit 9e67bc6115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

View File

@ -1518,7 +1518,7 @@ class Image(Element):
tooltip=tooltip) tooltip=tooltip)
return return
def Update(self, filename=None, data=None): def Update(self, filename=None, data=None, size=(None,None)):
if filename is not None: if filename is not None:
image = tk.PhotoImage(file=filename) image = tk.PhotoImage(file=filename)
elif data is not None: elif data is not None:
@ -1531,9 +1531,8 @@ class Image(Element):
# image = data # image = data
else: else:
return return
width, height = image.width(), image.height() width, height = size[0] or image.width(), size[1] or image.height()
self.tktext_label.configure(image=image, width=width, height=height) self.tktext_label.configure(image=image, width=width, height=height)
# self.tktext_label.configure(image=image)
self.tktext_label.image = image self.tktext_label.image = image
def __del__(self): def __del__(self):