.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_ui/viz_combobox.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_combobox.py: ======== ComboBox ======== This example shows how to use the Combobox UI. We will demonstrate how to create ComboBoxes for selecting colors for a label. First, some imports. .. GENERATED FROM PYTHON SOURCE LINES 11-15 .. code-block:: Python from fury import ui, window from fury.data import fetch_viz_icons .. GENERATED FROM PYTHON SOURCE LINES 16-17 First we need to fetch some icons that are included in FURY. .. GENERATED FROM PYTHON SOURCE LINES 17-20 .. code-block:: Python fetch_viz_icons() .. GENERATED FROM PYTHON SOURCE LINES 21-22 First, we create a label. .. GENERATED FROM PYTHON SOURCE LINES 22-32 .. code-block:: Python label = ui.TextBlock2D( position=(200, 300), font_size=40, color=(1, 0.5, 0), justification="center", vertical_justification="top", text="FURY rocks!!!", ) .. GENERATED FROM PYTHON SOURCE LINES 33-35 Now we create a dictionary to store colors as its key and their RGB values as its value. .. GENERATED FROM PYTHON SOURCE LINES 35-46 .. code-block:: Python colors = { "Violet": (0.6, 0, 0.8), "Indigo": (0.3, 0, 0.5), "Blue": (0, 0, 1), "Green": (0, 1, 0), "Yellow": (1, 1, 0), "Orange": (1, 0.5, 0), "Red": (1, 0, 0), } .. GENERATED FROM PYTHON SOURCE LINES 47-51 ComboBox =================== Now we create a ComboBox UI component for selecting colors. .. GENERATED FROM PYTHON SOURCE LINES 51-59 .. code-block:: Python color_combobox = ui.ComboBox2D( items=list(colors.keys()), placeholder="Choose Text Color", position=(75, 50), size=(250, 150), ) .. GENERATED FROM PYTHON SOURCE LINES 60-64 Callbacks ================================== Now we create a callback for setting the chosen color. .. GENERATED FROM PYTHON SOURCE LINES 64-74 .. code-block:: Python def change_color(combobox): label.color = colors[combobox.selected_text] # `on_change` callback is set to `change_color` method so that # it's called whenever a different option is selected. color_combobox.on_change = change_color .. GENERATED FROM PYTHON SOURCE LINES 75-79 Show Manager ================================== Now we add label and combobox to the scene. .. GENERATED FROM PYTHON SOURCE LINES 79-91 .. code-block:: Python current_size = (400, 400) showm = window.ShowManager(size=current_size, title="ComboBox UI Example") showm.scene.add(label, color_combobox) # To interact with the UI, set interactive = True interactive = False if interactive: showm.start() window.record(showm.scene, out_path="combobox_ui.png", size=(400, 400)) .. _sphx_glr_download_auto_examples_07_ui_viz_combobox.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_combobox.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_combobox.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_