• <legend id='NAQWk'><style id='NAQWk'><dir id='NAQWk'><q id='NAQWk'></q></dir></style></legend>
  • <tfoot id='NAQWk'></tfoot>

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

        • <bdo id='NAQWk'></bdo><ul id='NAQWk'></ul>

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

      2. un_active 按钮,直到函数在 kivy 中完成

        时间:2023-10-09
          <tbody id='sJMij'></tbody>
            • <small id='sJMij'></small><noframes id='sJMij'>

              <tfoot id='sJMij'></tfoot>

                <bdo id='sJMij'></bdo><ul id='sJMij'></ul>
              • <legend id='sJMij'><style id='sJMij'><dir id='sJMij'><q id='sJMij'></q></dir></style></legend>
                <i id='sJMij'><tr id='sJMij'><dt id='sJMij'><q id='sJMij'><span id='sJMij'><b id='sJMij'><form id='sJMij'><ins id='sJMij'></ins><ul id='sJMij'></ul><sub id='sJMij'></sub></form><legend id='sJMij'></legend><bdo id='sJMij'><pre id='sJMij'><center id='sJMij'></center></pre></bdo></b><th id='sJMij'></th></span></q></dt></tr></i><div id='sJMij'><tfoot id='sJMij'></tfoot><dl id='sJMij'><fieldset id='sJMij'></fieldset></dl></div>
                  本文介绍了un_active 按钮,直到函数在 kivy 中完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在为 UI 使用 kivy.有一个耗时的函数,当它运行时,kivy ui 会变黑,所以我使用了线程.我想禁用按钮,直到耗时功能完成,然后再次启用按钮.我一直在使用类似下面的东西:

                  I am using kivy for UI. there is a Time_consuming function and when it runs, kivy ui will goes in black, so I used Threading. I want to disable buttons until Time_consuming function finishes, and then enable button again. I have been used something like below:

                  from threading import Thread
                  from kivy.clock import Clock
                  from functools import partial
                  
                     def run():
                          self.run_button.disabled=True
                          self.back_button.disabled=True
                  
                          t=Thread(target=Time_consuming(), args=())
                          t.start()
                  
                          Clock.schedule_interval(partial(disable, t.isAlive()), 8)
                  
                      def disable(t, what):
                          print(t)
                          if not t:
                              self.run_button.disabled=False
                              self.back_button.disabled=False
                  

                  但这不起作用,即使 Time_sumption() 完成,disable() 中的 t.isAlive() 也是 True.问题出在哪里?

                  but this dose not work, t.isAlive() in disable() even when Time_consuming() finishes, is True. where is the problem ?

                  问题2:另一个问题是,Clock.schedule_interval 会一直运行下去.功能完成后如何停止?

                  question2: another problem is, Clock.schedule_interval will continue to run for ever. how can stop it when function finished?

                  推荐答案

                  我发现:

                  问题1:传递 t 而不是 t.isAlive().this :

                  question1: pass t instead of t.isAlive().this :

                  Clock.schedule_interval(partial(disable, t.isAlive()), 8)
                  

                  改为:

                  Clock.schedule_interval(partial(disable, t), 8)
                  

                  问题2:如果disable()返回False,调度将被取消,不再重复.

                  question2: If the disable() returns False, the schedule will be canceled and won’t repeat.

                  def run_model():
                      self.run_button.disabled=True
                      self.back_button.disabled=True
                  
                      t=Thread(target=run, args=())
                      t.start()
                  
                      Clock.schedule_interval(partial(disable, t), 8)
                  
                  def disable(t, what):
                      if not t.isAlive():
                          self.run_button.disabled=False
                          self.back_button.disabled=False
                          return False
                  

                  这篇关于un_active 按钮,直到函数在 kivy 中完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Kivy - 创建新的小部件并设置其位置和大小 下一篇:Kivy - 为 reStructuredText 创建样式按钮

                  相关文章

                  最新文章

                1. <small id='HYScT'></small><noframes id='HYScT'>

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

                2. <tfoot id='HYScT'></tfoot>
                  1. <legend id='HYScT'><style id='HYScT'><dir id='HYScT'><q id='HYScT'></q></dir></style></legend>