In [1]:
%gui asyncio
from flexx import flx
flx.init_notebook()
Widgets can be inserted into the notebook by making them a cell output:
In [2]:
b = flx.Button(text='foo')
b
Out[2]:
Widgets have many properties to modify their appearance and behavior:
In [3]:
b.set_text('click me!')
None # suppress output
In [4]:
with flx.HBox() as hbox:
slider = flx.Slider(flex=1)
progress = flx.ProgressBar(flex=3, value=0.7)
hbox
Out[4]:
In [5]:
@slider.reaction('value')
def show_slider_value(*events):
progress.set_value(slider.value) # or events[-1].new_value
In [6]:
class MyWidget2(flx.Widget):
def init(self):
with flx.HBox():
self._slider = flx.Slider(flex=1)
self._progress = flx.ProgressBar(flex=3)
@flx.reaction
def show_slider_value(self):
self._progress.set_value(self._slider.value / 2)
MyWidget2(style='min-height:20px')
Out[6]:
In [7]:
w3 = flx.launch(MyWidget2)
In [8]:
from flexxamples.demos.drawing import Drawing
Drawing(style='height:100px') # Draw using the mouse below!
Out[8]:
In [9]:
from flexxamples.demos.twente import Twente
Twente(style='height:300px')
Out[9]:
Since apps are really just Widgets, they can be embedded in larger apps with ease:
In [10]:
from flexxamples.demos.drawing import Drawing
from flexxamples.demos.twente import Twente
from flexxamples.howtos.splitters import Split
with flx.TabLayout(style='height:300px') as w4: # min-height does not seem to work very well for panel-based layouts
Twente(title='Twente', flex=1)
Drawing(title='Drawing', flex=1)
Split(title='Split', flex=1)
w4
Out[10]:
In [ ]: