久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

    2. <legend id='M7Ec0'><style id='M7Ec0'><dir id='M7Ec0'><q id='M7Ec0'></q></dir></style></legend>
        <bdo id='M7Ec0'></bdo><ul id='M7Ec0'></ul>

      <tfoot id='M7Ec0'></tfoot>

        Kivy:標簽文本在 for 循環期間不更新

        Kivy: Label text does not update during for-loop(Kivy:標簽文本在 for 循環期間不更新)
        <i id='sWdyG'><tr id='sWdyG'><dt id='sWdyG'><q id='sWdyG'><span id='sWdyG'><b id='sWdyG'><form id='sWdyG'><ins id='sWdyG'></ins><ul id='sWdyG'></ul><sub id='sWdyG'></sub></form><legend id='sWdyG'></legend><bdo id='sWdyG'><pre id='sWdyG'><center id='sWdyG'></center></pre></bdo></b><th id='sWdyG'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sWdyG'><tfoot id='sWdyG'></tfoot><dl id='sWdyG'><fieldset id='sWdyG'></fieldset></dl></div>
          <tfoot id='sWdyG'></tfoot>

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

              <tbody id='sWdyG'></tbody>
                <bdo id='sWdyG'></bdo><ul id='sWdyG'></ul>
                1. <legend id='sWdyG'><style id='sWdyG'><dir id='sWdyG'><q id='sWdyG'></q></dir></style></legend>

                  本文介紹了Kivy:標簽文本在 for 循環期間不更新的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我在 for 循環期間嘗試更新標簽文本時遇到問題.有類似的條目(例如:Update properties of a kivy widget while運行代碼),但它們似乎并不完全適合我的問題(或者我錯過了重點......).我運行以下代碼:

                  I have an issue when I try to update a label text during a for-loop. There are similar entries (e.g.: Update properties of a kivy widget while running code) but they do not seem to fit my issue exactly (or I missed the point…). I run following code:

                  *.py:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.properties import StringProperty
                  #from time import sleep
                  
                  class MyBox(BoxLayout):
                      tobeupd = StringProperty()
                  
                      def __init__(self,*args,**kwargs):
                          super(MyBox,self).__init__(*args,**kwargs)
                          self.tobeupd = '#'
                  
                      def upd_ltxt(self):
                          for i in range(1,10):
                              self.tobeupd = str(i)
                              print(self.tobeupd)
                              input('Write something: ')  # new line, see edit below
                              #sleep(0.5) 
                  
                  class updApp(App):
                      def build(self):
                          return MyBox()
                  
                  if __name__ == '__main__':
                      updApp().run() 
                  

                  *.kv

                  <MyBox>:
                      orientation: 'horizontal'
                      cols: 2
                      Label:
                          text: root.tobeupd
                      Button:
                          text: 'Start Update'
                          on_release: root.upd_ltxt()
                  

                  雖然打印"語句會定期更新 shell,但標簽文本僅在 for 循環結束時更新.誰能向我解釋為什么 Kivy 會這樣工作以及我如何克服這個問題?

                  Whereas the ‘print’ statement updates the shell regularly, the label text updates at the end of the for-loop only. Can anyone explain to me why Kivy works this way and how I can overcome this problem?

                  根據 PM2Ring 和 Gugas,我更改了代碼以避免睡眠功能.如果我要求用戶在循環繼續之前輸入一些內容,問題仍然存在.這些值在 shell 中更新,但不在標簽上.

                  According to PM2Ring and Gugas, I changed the code in order to avoid the sleep-function. The problem remains if I ask the user to enter something before the loop can be continued. The values are updated in the shell but not on the label.

                  推薦答案

                  您可以為此使用 threading.
                  當您在 kivy 中執行循環或等待輸入時,主線程正在等待,并且不會在應用程序上更新任何內容.threading 會阻止這種情況.
                  使用 threading 在主線程之外創建另一個線程.
                  示例:

                  You can use threading for this.
                  When you do a loop or wait for an input in kivy, the main thread is waiting, and nothing will update on the app. threading will prevent that.
                  Use threading to make another thread besides the main thread.
                  Example:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.properties import StringProperty
                  from kivy.lang import Builder
                  import threading
                  
                  Builder.load_string('''
                  
                  <MyBox>:
                      orientation: 'horizontal'
                      cols: 2
                      Label:
                          text: root.tobeupd
                      Button:
                          text: 'Start Update'
                          on_release: root.upd_ltxt()
                  
                  ''')
                  
                  class MyBox(BoxLayout):
                      tobeupd = StringProperty()
                  
                      def __init__(self,*args,**kwargs):
                          super(MyBox,self).__init__(*args,**kwargs)
                          self.tobeupd = '#'
                  
                      def upd_ltxt(self):
                          threading.Thread(target=self.update_label).start()
                  
                      def update_label(self):
                          for i in range(1,10):
                              print(self.tobeupd)
                              self.tobeupd = str(i)
                              input('Write something: ')  # new line, see edit below
                  
                  
                  
                  class updApp(App):
                      def build(self):
                          return MyBox()
                  
                  if __name__ == '__main__':
                      updApp().run()
                  

                  現在值得一提的是,即使第一個尚未完成,您也可以繼續按下按鈕并啟動線程.這可能是不受歡迎的行為.
                  這可以通過在線程開始時禁用按鈕并在結束時再次啟用它來防止.

                  Now its worth mentioning that you can keep pushing the button and start threads, even if the first did not finish yet. This might be an unwanted behavior.
                  This can be prevented by disabling the button in the beginning of the thread, and enabling it again at the end.

                  在kv中給按鈕一個id:

                  Give the button an id in kv:

                  Button:
                      id: updatebutton
                      text: 'Start Update'
                      on_release: root.upd_ltxt()
                  

                  在線程中這樣做:

                  def update_label(self):
                  
                      self.ids.updatebutton.disabled = True
                  
                      for i in range(1,10):
                          self.tobeupd = str(i)
                          input('Write something: ')
                  
                      self.ids.updatebutton.disabled = False
                  

                  這篇關于Kivy:標簽文本在 for 循環期間不更新的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <i id='AeRQY'><tr id='AeRQY'><dt id='AeRQY'><q id='AeRQY'><span id='AeRQY'><b id='AeRQY'><form id='AeRQY'><ins id='AeRQY'></ins><ul id='AeRQY'></ul><sub id='AeRQY'></sub></form><legend id='AeRQY'></legend><bdo id='AeRQY'><pre id='AeRQY'><center id='AeRQY'></center></pre></bdo></b><th id='AeRQY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AeRQY'><tfoot id='AeRQY'></tfoot><dl id='AeRQY'><fieldset id='AeRQY'></fieldset></dl></div>
                2. <legend id='AeRQY'><style id='AeRQY'><dir id='AeRQY'><q id='AeRQY'></q></dir></style></legend>

                          • <bdo id='AeRQY'></bdo><ul id='AeRQY'></ul>
                            <tfoot id='AeRQY'></tfoot>
                              <tbody id='AeRQY'></tbody>

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

                            主站蜘蛛池模板: 在线午夜| 国产精品久久久久久久午夜 | 亚洲国产精品人人爽夜夜爽 | 一区二区三区国产视频 | 蜜臀久久99精品久久久久久宅男 | 久久久国 | 激情国产| 日本午夜免费福利视频 | 日韩一区欧美一区 | 国产精品高潮呻吟久久 | 亚洲一区| 国产乱码精品一区二区三区忘忧草 | 国产精品久久久久久久午夜片 | 成人在线a | 色综合一区 | 午夜免费在线观看 | 日屁视频 | 九七午夜剧场福利写真 | 国产乱码精品一品二品 | 欧美性吧| 国产精品久久久久久久久久99 | 天堂色 | 亚洲欧美在线视频 | 91在线网站 | 中文字幕一区二区视频 | 天天色综网 | 精品伊人久久 | 观看av | 成人性生交大片免费看r链接 | 超碰97免费| 麻豆av电影网 | 91精品国产91久久久久久最新 | 亚洲精品国产第一综合99久久 | 欧美大片一区二区 | 日韩免费福利视频 | 欧美久久久网站 | 亚洲视频免费观看 | 国产日韩欧美在线观看 | 日韩午夜网站 | 日韩精品在线观看视频 | 在线中文字幕第一页 |