从自己的类调用 iPyWidgets 不显示



我尝试在我自己的类上调用iPyWidgets中的按钮,但不幸的是它不会显示该小部件。但是当我直接在控制台(Jupyterhub(中调用小部件代码时,它会显示按钮。这是我的代码

callButton.py

from here.analysis.testUI import TestUI
def call_button():
test = TestUI()
go = test.button()
go

testUi.py

from ipywidgets import widgets
from IPython.display import display
from ipywidgets import Button, HBox, VBox, Layout, Button, Text, Textarea
class TestUI():
def __init__(self):
print("Just initialized")
def button(self):
#Maybe a return is not needed, but it also doesn´t work without a return
return widgets.Button(description = 'clear', layout=Layout(width='20%', height='100%'))

我在 Python 控制台中像这样调用它:

from here.analysis.callButton import call_button
call_button()

那么为什么按钮没有显示呢?我错过了什么吗?

确保在call_button.py中使用display(button)显式显示按钮

最新更新