我尝试通过我自己的类从 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)
显式显示按钮
关于python - 从自己的类调用 iPyWidgets 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59803555/