Unable to refresh Image.src #1338
-
My application requires to generate images on the fly and the output is display on a Image Control. However, everytime my image is generated, calling Image.src = does not refresh the image. The Image control is still showing the first image. Code example to reproduce the issue: import flet as ft
from flet import Theme, Icon
import logging
import os
from PIL import Image
from processpiper.text2diagram import render
logging.getLogger("flet_core").setLevel(logging.ERROR)
def main(page: ft.page):
page.theme_mode = ft.ThemeMode.LIGHT
page.title = "Process Piper"
page.scroll = ft.ScrollMode.ADAPTIVE
page.window_height = 800
page.window_width = 1200
page.update()
def generate_diagram(e):
diagram_text = user_input.value
try:
output_image_file = "diagram.png"
generated_code, generated_image = render(diagram_text, output_image_file)
output_image.src = output_image_file
output_image.update()
page.update()
except Exception as e:
log_text.value = log_text.value + "\n" + str(e)
page.update()
test_text = """
title: Make pizza process
lane: Pizza Shop
(start) as start
[Put the pizza in the oven] as put_pizza_in_oven
[Check to see if pizza is done] as check_pizza_done
<Done baking?> as done_baking
[Take the pizza out of the oven] as take_pizza_out_of_oven
(end) as end
start->put_pizza_in_oven->check_pizza_done->done_baking
done_baking-"Yes"->take_pizza_out_of_oven->end
done_baking-"No"->put_pizza_in_oven
"""
user_input = ft.TextField(
label="Enter text here",
value=test_text,
multiline=True,
text_size=11,
icon=ft.icons.TEXT_FIELDS_SHARP,
)
generate_button = ft.ElevatedButton(
"Generate", on_click=generate_diagram, icon=ft.icons.DIRECTIONS_RUN
)
output_image = ft.Image("Output Image")
log_text = ft.TextField(
label="Log Messages",
value="",
multiline=True,
read_only=True,
text_size=11,
color="black",
bgcolor="white",
)
page.add(
user_input,
generate_button,
output_image,
log_text,
)
ft.app(target=main)
The render() method regenerates the image based on the diagram_text. However, the To reproduce the bug,
I expect the output_image get updated and showing the latest image. Additional information you deem important (e.g. issue happens only occasionally): Flet version (
Operating system: Windows Additional environment details: |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
That seems strange. If it still doesn't work, then build up some small working code sample with the issue, so we/I can give it a better look. |
Beta Was this translation helpful? Give feedback.
-
Same result even if I use output_img.update() |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
@ndonkoHenri, I have provided a complete code sample that reproduce the issue. See the original post above. Thanks! |
Beta Was this translation helpful? Give feedback.
-
@csgoh by changing image file contents you are not changing Flet control properties. Solution: every time you generate new image change its filename too. |
Beta Was this translation helpful? Give feedback.
@csgoh by changing image file contents you are not changing Flet control properties.
output_image.src
and other image properties stay the same as a resultpage.update()
does nothing.Solution: every time you generate new image change its filename too.