<small id='s06rI'></small><noframes id='s06rI'>

      1. <legend id='s06rI'><style id='s06rI'><dir id='s06rI'><q id='s06rI'></q></dir></style></legend>

        • <bdo id='s06rI'></bdo><ul id='s06rI'></ul>
        <i id='s06rI'><tr id='s06rI'><dt id='s06rI'><q id='s06rI'><span id='s06rI'><b id='s06rI'><form id='s06rI'><ins id='s06rI'></ins><ul id='s06rI'></ul><sub id='s06rI'></sub></form><legend id='s06rI'></legend><bdo id='s06rI'><pre id='s06rI'><center id='s06rI'></center></pre></bdo></b><th id='s06rI'></th></span></q></dt></tr></i><div id='s06rI'><tfoot id='s06rI'></tfoot><dl id='s06rI'><fieldset id='s06rI'></fieldset></dl></div>
        <tfoot id='s06rI'></tfoot>

        暂停 Jupyter Notebook 小部件,等待用户输入

        Pause Jupyter Notebook widgets, waiting for user input(暂停 Jupyter Notebook 小部件,等待用户输入)

          <tfoot id='sdvZ9'></tfoot>

              <tbody id='sdvZ9'></tbody>
              <bdo id='sdvZ9'></bdo><ul id='sdvZ9'></ul>
              <legend id='sdvZ9'><style id='sdvZ9'><dir id='sdvZ9'><q id='sdvZ9'></q></dir></style></legend>

                <small id='sdvZ9'></small><noframes id='sdvZ9'>

                • <i id='sdvZ9'><tr id='sdvZ9'><dt id='sdvZ9'><q id='sdvZ9'><span id='sdvZ9'><b id='sdvZ9'><form id='sdvZ9'><ins id='sdvZ9'></ins><ul id='sdvZ9'></ul><sub id='sdvZ9'></sub></form><legend id='sdvZ9'></legend><bdo id='sdvZ9'><pre id='sdvZ9'><center id='sdvZ9'></center></pre></bdo></b><th id='sdvZ9'></th></span></q></dt></tr></i><div id='sdvZ9'><tfoot id='sdvZ9'></tfoot><dl id='sdvZ9'><fieldset id='sdvZ9'></fieldset></dl></div>
                • 本文介绍了暂停 Jupyter Notebook 小部件,等待用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I have the same issue as TheInterestedOne asked here.

                  I need to create two buttons for the user, and suggest that the user clicks one of the two buttons in the loop; so that the next iteration of the loop occurs only after the user's choice.

                  I read this source, but I can't make it work for buttons. I don't understand, how the widget attribute changes in the case of using buttons.

                  from functools import wraps
                  def yield_for_change(widget, attribute):
                      def f(iterator):
                          @wraps(iterator)
                          def inner():
                              i = iterator()
                              def next_i(change):
                                  try:
                                      i.send(change.new)
                                  except StopIteration as e:
                                      widget.unobserve(next_i, attribute)
                              widget.observe(next_i, attribute) //**button.on_click(on_button_clicked) 
                                                                                  may be?**
                              # start the generator
                              next(i)
                          return inner
                      return f
                  
                  
                  from ipywidgets import Button
                  button=Button()
                  
                  
                  def on_button_clicked():
                      print("Button clicked.")
                  
                  
                  @yield_for_change(button, 'value')
                  def f():
                      for i in range(10):
                          print('did work %s'%i)
                          x = yield
                          button.on_click(on_button_clicked)
                  

                  解决方案

                  This version uses awaitio and is modified for buttons.

                  from ipywidgets import Button
                  import asyncio
                  
                  def wait_for_change(widget):
                      future = asyncio.Future()
                      def getvalue(change):
                          future.set_result(change.description)
                          widget.on_click(getvalue, remove=True) 
                          # we need to free up the binding to getvalue to avoid an InvalidState error
                          # buttons don't support unobserve
                          # so use `remove=True` 
                      widget.on_click(getvalue)
                      return future
                  
                  button = Button(description="wow")
                  
                  list_to_tag = ["one", "two", "three", "four"]
                  
                  async def f():
                      for i in list_to_tag:
                          print("going to tag {}".format(i))
                          x = await wait_for_change(button)
                          print("tagged {} with {}".format(i, x))
                          print()
                  
                  asyncio.create_task(f())
                  button
                  

                  这篇关于暂停 Jupyter Notebook 小部件,等待用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  • <tfoot id='pDviw'></tfoot>
                        <tbody id='pDviw'></tbody>
                        <bdo id='pDviw'></bdo><ul id='pDviw'></ul>

                        • <i id='pDviw'><tr id='pDviw'><dt id='pDviw'><q id='pDviw'><span id='pDviw'><b id='pDviw'><form id='pDviw'><ins id='pDviw'></ins><ul id='pDviw'></ul><sub id='pDviw'></sub></form><legend id='pDviw'></legend><bdo id='pDviw'><pre id='pDviw'><center id='pDviw'></center></pre></bdo></b><th id='pDviw'></th></span></q></dt></tr></i><div id='pDviw'><tfoot id='pDviw'></tfoot><dl id='pDviw'><fieldset id='pDviw'></fieldset></dl></div>

                            <small id='pDviw'></small><noframes id='pDviw'>

                          1. <legend id='pDviw'><style id='pDviw'><dir id='pDviw'><q id='pDviw'></q></dir></style></legend>