Skip to content

Update userdata.get() workaround example on wiki #590

@matheustmattioli

Description

@matheustmattioli

Hello! I am opening this issue because the workaround example on wiki for the google colab userdata.get() is outdated. The ipywidget library does not support the on_submit anymore.

What you think of updating the example like below? Basically we need to change the .on_submit for .observe and add continuous_update=False.

import os

import ipywidgets as widgets
from IPython.display import clear_output, display


def input_secret(secret_name):
  def handle_submit(sender):
      user_value = sender['new']
      os.environ[secret_name] = user_value
      print(f"Environment variable {secret_name} set")
      with output_area:
          clear_output()

  # Create a text input widget
  text_input = widgets.Text(
      value='',
      placeholder=f'Value for {secret_name}',
      description=f'Secret Value',
      disabled=False,
      continuous_update=False
  )

  # Create an output widget to control clearing
  output_area = widgets.Output()

  # Link the submit event to the handler function
  text_input.observe(handle_submit, names='value')

  # Display the widget inside the output area, then display the output area
  with output_area:
      display(text_input)
  display(output_area)

input_secret("GEMINI_API_KEY")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions