Python 使用“交互”在滑块中设置默认值
我试图根据文档,在jupyter笔记本中使用interact为滑块设置默认值 虽然“最小”、“最大”和“步长”的值工作正常Python 使用“交互”在滑块中设置默认值,python,ipython,jupyter-notebook,Python,Ipython,Jupyter Notebook,我试图根据文档,在jupyter笔记本中使用interact为滑块设置默认值 虽然“最小”、“最大”和“步长”的值工作正常 from ipywidgets import interact def f(x): return x interact(f, x=(5,20,5)) 我无法传递初始默认值15,我总是在尝试执行以下操作时出错: from ipywidgets import interact def f(x): return x interact(f, x=(5,20
from ipywidgets import interact
def f(x):
return x
interact(f, x=(5,20,5))
我无法传递初始默认值15,我总是在尝试执行以下操作时出错:
from ipywidgets import interact
def f(x):
return x
interact(f, x=(5,20,5,15))
或
错误消息如下:
ValueError:(5,20,5,15)无法转换为小部件
或
语法错误
我遗漏了什么?看看博克文档 根据您的需要转换此代码:
from bokeh.io import output_file, show
from bokeh.layouts import widgetbox
from bokeh.models.widgets import Slider
output_file("slider.html")
slider = Slider(start=0, end=10, value=1, step=.1, title="Stuff")
show(widgetbox(slider))
我希望这对你有帮助。我在路上。如果你需要更多的支持,请告诉我
亲切问候,,
Fabian我正在jupyter笔记本上使用Python 3.4,使用Linux。我让这个工作:
from ipywidgets import interact, widgets
def f(x):
return x
interact(f, x=widgets.IntSlider(min=5,max=20,step=5,value=15));
感谢您的输入,但我的问题似乎是基于将滑块参数传递给函数。在滑块调用中直接使用value参数没有问题。这正是我想要的,谢谢。可以在函数中执行
打印(“Value:,x)
。
from ipywidgets import interact, widgets
def f(x):
return x
interact(f, x=widgets.IntSlider(min=5,max=20,step=5,value=15));