Python:Interact下拉列表-如何引用输出
嗨,我有下面的下拉列表:Python:Interact下拉列表-如何引用输出,python,dropdown,ipywidgets,Python,Dropdown,Ipywidgets,嗨,我有下面的下拉列表: from ipywidgets import interact, interactive, fixed, interact_manual import ipywidgets as widgets def f(Books): return Books interact(f, Books=['a','b','c','d']); 这将填充一个下拉列表,允许用户从a、b、c、d中进行选择 假设用户从四个选项中选择一个 你如何参考结果 我想在其他公式中使用下拉列表的
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
def f(Books):
return Books
interact(f, Books=['a','b','c','d']);
这将填充一个下拉列表,允许用户从a、b、c、d中进行选择
假设用户从四个选项中选择一个
你如何参考结果
我想在其他公式中使用下拉列表的输出作为变量
前
冒着推荐一些通常很糟糕的做法的风险,我会在这里使用一个全局变量。它快速而简单,考虑到iPython的交互式/原型化特性,许多反对全局变量的常见论点并不是非常重要 基本上,每次更改Interactive小部件输入上的变量时,都会调用f。因此,您只需在函数中更新此变量:
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
myvar = ''
def f(Books):
global myvar
myvar = Books
return Books
interact(f, Books=['a','b','c','d']);
您正在使用什么GUI库?interact从何而来?从ipywidgets导入interact、interactive、fixed、interact\u手动导入ipywidgets作为小部件
from ipywidgets import interact, interactive, fixed, interact_manual
import ipywidgets as widgets
myvar = ''
def f(Books):
global myvar
myvar = Books
return Books
interact(f, Books=['a','b','c','d']);