You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!
I'm testing flat and trying to write a simple program that renders an input expression to a graphic file using flex and matplotlib.
We accept a string with equation from the user (for example 'x+1=3'), render it to a png file and output it to the Image widget. So far everything is correct. But if we change the equation in the input widget and press the render button again, the Image widget content does not change. However, the new file is rendered correctly. But the widget does not show it.
Thanks in advance for your help!
Code sample
importfletasftimportsympyasspimportmatplotlib.pyplotaspltimportmatplotlibmatplotlib.use('Agg')
defmain(page: ft.Page):
page.window.width=1280page.window.height=720output_file='expression_output'rendered_image=ft.Image(src='expression_output.png')
defrender_latex(e):
# Divide the equation into left and right partstry:
left_side, right_side=equation_field.value.split('=')
left_expr=sp.sympify(left_side.strip())
right_expr=sp.sympify(right_side.strip())
eq=sp.Eq(left_expr, right_expr)
exceptExceptionase:
print(f"Error processing equation: {e}")
returnlatex_expr=sp.latex(eq)
# Matplotlib renderingfig, ax=plt.subplots(figsize=(5, 2))
ax.text(0.5, 0.5, f"${latex_expr}$", fontsize=18, ha='center', va='center', color='black')
ax.axis('off')
plt.savefig(output_file, bbox_inches='tight', pad_inches=0.1, transparent=True)
plt.close(fig)
print(f"Image saved as '{output_file}'")
main_container.content.controls.append(rendered_image)
page.update()
main_container.content.controls.remove(rendered_image)
# Text fieldequation_field=ft.TextField(
label='Enter the equation',
hint_text='Equation',
)
# Render buttonrender_button=ft.ElevatedButton(
text='Render',
on_click=render_latex
)
# Main containermain_container=ft.Container(
content=ft.Column(
controls=[
equation_field, render_button
]
)
)
page.add(main_container)
ft.app(target=main)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
Hi!
I'm testing flat and trying to write a simple program that renders an input expression to a graphic file using flex and matplotlib.
We accept a string with equation from the user (for example 'x+1=3'), render it to a png file and output it to the Image widget. So far everything is correct. But if we change the equation in the input widget and press the render button again, the Image widget content does not change. However, the new file is rendered correctly. But the widget does not show it.
Thanks in advance for your help!
Code sample
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions