Jupyter Notebook HBox不在功能内显示

时间:2019-04-02 07:48:29

标签: python python-3.x jupyter-notebook ipython ipywidgets

嘿,我有一个ipynb,可以在盒子中显示我的小部件。一切都很好,并且代码运行良好。但是在按下一个键之后,on_button_clicked函数将完成一些工作。其中一些功能是可以重新打印我的按钮和图像小部件的功能。其完全相同的代码,但未显示小部件。我是python和jynb的新手,希望您能给我一些提示。

首次加载开始的代码:

pattern = '*.png' 
liste =fnmatch.filter(os.listdir(dir_path), pattern)
file = open(dir_path+liste[counter], "rb")
image = file.read()
abcd=widgets.Image(
    value=image,
    format='png',
) 

button_next = widgets.Button(description="next", layout=Layout(width='50%', 
height='80px'),button_style='primary')
button_next.on_click(on_button_clicked_next)

button_previous = widgets.Button(description="previous", 
layout=Layout(width='50%', height='80px'),button_style='primary')
button_previous.on_click(on_button_clicked_previous)

button_wrong = widgets.Button(description="wrong", layout=Layout(flex='1 1 
20%', height='80px'), button_style='danger')
button_wrong.on_click(on_button_clicked_wrong)

button_correct = widgets.Button(description="correct", layout=Layout(flex='1 
1 20%', height='80px'), button_style='success')
button_correct.on_click(on_button_clicked_correct)

button_unkown = widgets.Button(description="Unkown suggestion")
button_unkown.on_click(on_button_clicked_unkown)

items_upside = [ 
     button_previous,
     widgets.Image(value=image,format='png', layout=Layout(flex='1 1 60%')),
     button_next,
 ]

items_downside = [
     button_correct,
     button_wrong
 ]

 box_layout = Layout(display='center',align_items='center', width='100%')
 box_upside = Box(children=items_upside, layout=box_layout)
 box_downside = Box(children=items_downside, layout=box_layout)
 VBox([box_upside, box_downside])

键:

def on_button_clicked_previous(self):
  global dir_path
  clear_output()
  global counter
  counter=counter-1
  path = (os.listdir(dir_path)[counter])
  execute()

Exectue():

Same Code from the upside (copy&paste) to rebuild the UI

这是第一次运行后不按任何按钮的外观,我应该如何在按钮动作后像其他图像一样浏览。

enter image description here

0 个答案:

没有答案