我在jupyter notebook中有以下代码,其中ipywidgets
7.5.1是一个登录掩码
from ipywidgets import widgets
class Login:
def __init__(self):
text21 = widgets.Text(description="username")
text22 = widgets.Text(description = "password")
self.button = widgets.Button(
description='Login NSG',
disabled=False,
button_style='info',
tooltip='Login with username and password',
)
self.vbox_conf = widgets.VBox(children=[text21, text22, self.button])
self.button.observe(self.login)
# alternative: self.button.observe(self.login, names='value')
display(self.vbox_conf)
def login(self, args):
print("test")
print(args)
login = Login()
它呈现一个登录掩码,但当我按下按钮时,什么也没有发生!没有打印出来,也没有在笔记本或日志窗口中
发生了什么以及如何解决这个问题
解决方案是:您必须使用方法
on_click
来处理被单击的按钮这是一个未记录的特性(或者至少在不完整且具有误导性的documentation中很难找到)
相关问题 更多 >
编程相关推荐