How to align widget buttons in IPython laptop

I have the following code code

from ipywidgets import widgets from IPython.display import display import numpy as np class Test(object): def __init__(self, arraylen): self.a = np.random.randn(arraylen) self.button = widgets.Button(description = 'Show') self.button.on_click(self.show) display(self.button) self.button1 = widgets.Button(description = 'Show1') self.button1.on_click(self.show) display(self.button1) def show(self, ev = None): np.savetxt('test',self.a) self.button.disabled = True test = Test(10) 

The output consists of two buttons in a column, as shown here: enter image description here

Would it also be possible to embed buttons in an HTML table (where could I select them in a row) or any other organization diagram? Perhaps it might look like this:

enter image description here

+5
source share
1 answer

You can use (a very simple example):

 from IPython.display import display from ipywidgets import widgets button1 = widgets.Button(description = 'Button1') button2 = widgets.Button(description = 'Button2') display(widgets.HBox((button1, button2))) 

Here you can find basic and more complete examples of using widgets. If you use Jupyter, you have to adapt some information ( from ipywidgets import widgets instead of from IPython.html import widgets , ...).

+9
source

All Articles