Consider 3 different ways to display text input using jupyter ipywidgets:
from ipywidgets import Text,HTML,Layout
from IPython.display import display
# Using the HTML widget
input_html = """
<html>
<head>
<body>
<input size=20 type="text" style="text-align:center" value="HTML">
</body>
</html>
"""
my_widget = HTML(value=input_html,layout=Layout(width='50%'))
display(my_widget)
# Using the Text widget, without specifying a layout
display(Text(value = "Text"))
# Using the Text widget, specifying a layout
mylayout = layout=Layout(
justify_content="center",
width="50%",
border="solid"
)
display(Text(value="Text/Layout ",layout=mylayout))
The ipywidgets.HTML
widget displays the input control with the text centered properly. I have not been able to find any combination of ipywidgets.Layout
or ipywidgets.Style
attributes that properly center text using the Text widget (or Textarea).
I have searched quite a bit for the answer, and have not had any luck. Text centering works well with other widgets like ipywidgets.Label
and ipywidgets.Button
. However, the Text widget does not appear to allow for text centering.
I have read through the documentation pages below, that treat Styling and Layouts:
https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Styling.html https://ipywidgets.readthedocs.io/en/stable/examples/Widget%20Layout.html
Finally, I have searched on google and Stackoverflow (directly) using search strings like: ipywidgets Text center ipywidgets Text text-align jupyter widgets center the text in a Text widget
I have not yet found an answer.
Thanks much for any help