jupyter-widgets / ipywidgets

Interactive Widgets for the Jupyter Notebook
https://ipywidgets.readthedocs.io
BSD 3-Clause "New" or "Revised" License
3.15k stars 949 forks source link

Setting a margin for a VBox #2097

Open jarthurEC opened 6 years ago

jarthurEC commented 6 years ago

I've created an array of widgets - a VBox which includes a series of HBoxes. That works fine. I would like to center the array on the output page. Is there a simple way to specify a margin for the left edge of that array?

jtpio commented 6 years ago

You can have a look at Layout and Styling of Jupyter widgets.

For example, something like the following could work (adding a margin):

from ipywidgets import HBox, Layout, VBox
items = [HBox([Label(f'{i}{j}') for i in range(4)]) for j in range(4)]
box = VBox(items, layout=Layout(margin='0 0 0 100px'))
box

Which gives:

image

jarthurEC commented 6 years ago

Thanks. This may be better than what I ended up doing, which was put spaces to the left of the first HBox in every row.

John

From: "Jeremy Tuloup" notifications@github.com To: "jupyter-widgets/ipywidgets" ipywidgets@noreply.github.com Cc: "John Howell" jhowell@earlham.edu, "Author" author@noreply.github.com Sent: Thursday, June 28, 2018 6:46:39 PM Subject: Re: [jupyter-widgets/ipywidgets] Setting a margin for a VBox (#2097)

You can have a look at [ https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html | Layout and Styling of Jupyter widgets ] .

For example, something like the following could work (adding a margin): from ipywidgets import HBox, Layout, VBox items = [HBox([Label( f ' { i }{ j } ' ) for i in range ( 4 )]) for j in range ( 4 )] box = VBox(items, layout = Layout( margin = ' 0 0 0 100px ' )) box

Which gives:

[ https://user-images.githubusercontent.com/591645/42064204-a25b9e78-7b35-11e8-9db1-6d112d0d3983.png ]

— You are receiving this because you authored the thread. Reply to this email directly, [ https://github.com/jupyter-widgets/ipywidgets/issues/2097#issuecomment-401195648 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/AKBIE27lyiefZDWUulWiwYjhbfRNVumjks5uBVzPgaJpZM4UjhQG | mute the thread ] .

-- John A. Howell, Ph.D., professor emeritus Department of Physics Earlham College Richmond, IN 47374 (Office) 765-983-1670 (FAX) 765-983-1691