Python 不修改原代码的widget布局
Python widget layout without modifying original code
我有以下原始代码,其中所有小部件仅沿一列显示,我想沿 2 列显示它们。
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from ipywidgets import Button, HBox, VBox
dW = widgets.Dropdown(options=['2', '1'])
rW = widgets.FloatText(200)
aW = widgets.FloatText(1)
@interact(D=dW, R=rW, A=aW)
def print_p(D, R, A):
dW = D
rW = R
aW = A
我已经阅读了文档,它建议使用以下格式:
left_box = VBox([dW, rW])
right_box = VBox([aW])
HBox([left_box, right_box])
有没有办法整合上面的代码,这样我就不需要改变原来的格式就可以看到2列了?
这里是答案:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual, Text
import ipywidgets as widgets
dW = widgets.Dropdown(options=['2', '3'])
rW = widgets.FloatText(200)
mW = widgets.FloatText()
left_box = VBox([dW, rW])
right_box = VBox([mW])
ui = HBox([left_box, right_box])
def print_p(Provvigione_Agente_EUR, R, M):
dW = Provvigione_Agente_EUR
rW = R
mW.value = int(dW)*int(rW)
out = widgets.interactive_output(print_p, {'Provvigione_Agente_EUR':dW, 'R':rW, 'M':mW})
display(ui, out)
我有以下原始代码,其中所有小部件仅沿一列显示,我想沿 2 列显示它们。
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
from ipywidgets import Button, HBox, VBox
dW = widgets.Dropdown(options=['2', '1'])
rW = widgets.FloatText(200)
aW = widgets.FloatText(1)
@interact(D=dW, R=rW, A=aW)
def print_p(D, R, A):
dW = D
rW = R
aW = A
我已经阅读了文档,它建议使用以下格式:
left_box = VBox([dW, rW])
right_box = VBox([aW])
HBox([left_box, right_box])
有没有办法整合上面的代码,这样我就不需要改变原来的格式就可以看到2列了?
这里是答案:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed, interact_manual, Text
import ipywidgets as widgets
dW = widgets.Dropdown(options=['2', '3'])
rW = widgets.FloatText(200)
mW = widgets.FloatText()
left_box = VBox([dW, rW])
right_box = VBox([mW])
ui = HBox([left_box, right_box])
def print_p(Provvigione_Agente_EUR, R, M):
dW = Provvigione_Agente_EUR
rW = R
mW.value = int(dW)*int(rW)
out = widgets.interactive_output(print_p, {'Provvigione_Agente_EUR':dW, 'R':rW, 'M':mW})
display(ui, out)