.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples\07_ui\viz_textbox.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_07_ui_viz_textbox.py: ============ UI Text Box ============ This example demonstrates how to create and customize 2D Text Boxes using the FURY UI elements. We'll explore different configurations such as single-line, multi-line, and styled text. .. GENERATED FROM PYTHON SOURCE LINES 10-14 .. code-block:: Python from fury.ui import TextBox2D from fury.window import Scene, ShowManager .. GENERATED FROM PYTHON SOURCE LINES 15-16 A Scene acts as a container for all our UI elements and 3D objects. .. GENERATED FROM PYTHON SOURCE LINES 16-18 .. code-block:: Python scene = Scene() .. GENERATED FROM PYTHON SOURCE LINES 19-21 1. Simple Single-Line Text Box We define a basic text box with a specified width, height, and color (red). .. GENERATED FROM PYTHON SOURCE LINES 21-30 .. code-block:: Python textbox_single = TextBox2D( width=20, height=1, text="Single line", position=(50, 450), color=(1, 0, 0), font_size=20, ) .. GENERATED FROM PYTHON SOURCE LINES 31-34 2. Multi-Line Text Box The text can span across multiple lines by using the newline character '\n'. We also increase the height to accommodate the extra lines. .. GENERATED FROM PYTHON SOURCE LINES 34-43 .. code-block:: Python textbox_multi = TextBox2D( width=20, height=3, text="Multi-line\nText box", position=(50, 300), color=(0, 0, 1), font_size=25, ) .. GENERATED FROM PYTHON SOURCE LINES 44-46 3. Static Text Box A standard text box that displays static text in black. .. GENERATED FROM PYTHON SOURCE LINES 46-55 .. code-block:: Python textbox_static = TextBox2D( width=20, height=2, text="Static Text box", position=(50, 200), color=(0, 0, 0), # Black color font_size=20, ) .. GENERATED FROM PYTHON SOURCE LINES 56-59 4. Styled Text Box We can customize the appearance by enabling bold, italic properties and setting the text justification to "center". .. GENERATED FROM PYTHON SOURCE LINES 59-71 .. code-block:: Python textbox_styled = TextBox2D( width=20, height=2, text="Bold & Italic\nCenter justification", position=(50, 100), color=(0, 0.5, 0), # Dark green color font_size=18, justification="center", bold=True, italic=True, ) .. GENERATED FROM PYTHON SOURCE LINES 72-74 After configuring our UI elements, we must add them to the scene so they will be rendered on the screen. .. GENERATED FROM PYTHON SOURCE LINES 74-79 .. code-block:: Python scene.add(textbox_single) scene.add(textbox_multi) scene.add(textbox_static) scene.add(textbox_styled) .. GENERATED FROM PYTHON SOURCE LINES 80-81 ShowManager handles the window creation, interaction, and rendering loop. .. GENERATED FROM PYTHON SOURCE LINES 81-88 .. code-block:: Python current_size = (800, 700) show_manager = ShowManager( scene=scene, size=current_size, title="FURY Text Box Example", ) .. GENERATED FROM PYTHON SOURCE LINES 89-90 Finally, we start the interactive rendering loop to display our UI. .. GENERATED FROM PYTHON SOURCE LINES 90-91 .. code-block:: Python show_manager.start() .. image-sg:: /auto_examples/07_ui/images/sphx_glr_viz_textbox_001.png :alt: viz textbox :srcset: /auto_examples/07_ui/images/sphx_glr_viz_textbox_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.160 seconds) .. _sphx_glr_download_auto_examples_07_ui_viz_textbox.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_textbox.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_textbox.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_textbox.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_