尝试创建带有一些输出的简单按钮,我尝试了以下代码
from IPython.display import display
def clicked():
print("button has been clicked!")
button_download = widgets.Button(description = 'Test Button')
button_download.on_click(clicked)
display(button_download)
但是当我单击按钮时,我看不到任何输出。
我发现了另一个可行的示例,但这太复杂了:
from IPython.display import display
button = widgets.Button(description="Click Me!")
output = widgets.Output()
display(button,output)
def on_button_clicked(b):
with output:
print("Button clicked.")
button.on_click(on_button_clicked)
我真的需要做output
的事情,以便在单击按钮时可以看到print
语句的输出吗?
系统为Jupyterlab 1.1.4。