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

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

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

          <bdo id='iUsD2'></bdo><ul id='iUsD2'></ul>
      1. <small id='iUsD2'></small><noframes id='iUsD2'>

        Kivy - 將標簽文本綁定到變量(僅限 Python)

        Kivy - Bind Label Text To Variable (Python Only)(Kivy - 將標簽文本綁定到變量(僅限 Python))
      2. <i id='tMRst'><tr id='tMRst'><dt id='tMRst'><q id='tMRst'><span id='tMRst'><b id='tMRst'><form id='tMRst'><ins id='tMRst'></ins><ul id='tMRst'></ul><sub id='tMRst'></sub></form><legend id='tMRst'></legend><bdo id='tMRst'><pre id='tMRst'><center id='tMRst'></center></pre></bdo></b><th id='tMRst'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tMRst'><tfoot id='tMRst'></tfoot><dl id='tMRst'><fieldset id='tMRst'></fieldset></dl></div>
          • <bdo id='tMRst'></bdo><ul id='tMRst'></ul>
          • <small id='tMRst'></small><noframes id='tMRst'>

            1. <tfoot id='tMRst'></tfoot>
                <tbody id='tMRst'></tbody>

              <legend id='tMRst'><style id='tMRst'><dir id='tMRst'><q id='tMRst'></q></dir></style></legend>

                  本文介紹了Kivy - 將標簽文本綁定到變量(僅限 Python)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我已經嘗試讓我的標簽自動更新很長一段時間了,我已經閱讀了十幾個 StackOverflow 問題,但無濟于事.

                  I have been trying to get my labels to auto-update themselves for quite a while now and I have read over a dozen StackOverflow questions but to no avail.

                  我有一個全局對象,其中包含一個整數值,我希望在其中一個小部件類中顯示該值并帶有標簽.

                  I have an global object that contains an integer value that I want to be displayed with a label inside of one of my widget classes.

                  小部件類如下所示:

                  class Battle(Widget):
                  
                      def __init__(self, **kwargs):
                          super(Battle, self).__init__(**kwargs)
                  
                          #Enemy Stats
                          self.enemyBar = BoxLayout(orientation="horizontal", size=(Window.width, Window.height/8), center_y = Window.height - self.height/2)
                          self.enemyBar.add_widget(Label(text=enemy.name))
                  
                          #Enemy Health Label
                          health_label = Label(text=str(enemy.health))
                          self.enemyBar.add_widget(health_label)
                          self.add_widget(self.enemyBar)
                  
                  
                      def update_health(instance, value):
                          health_label.text = str(enemy.health) #<-- Error happens here
                  
                      enemy.bind(health=update_health)
                  

                  enemy.health 的值在程序中改變時,我希望我的標簽也改變.我不想使用任何 kivy 語言,因為我更喜歡只有一個主 python 文件.

                  When the value of enemy.health is changed in the program, I want my label to change as well. I do not want to use any of the kivy language because I prefer having just one main python file.

                  敵人對象是使用實體類創建的.這是實體代碼:

                  The enemy object is created with an entity class. Here is the entity code:

                  class entity(Widget):
                      #entity creation
                      health = NumericProperty() 
                  
                      def __init__(self, health):
                          self.health = health
                  

                  當我運行代碼時,我按下一個按鈕,該按鈕調用一個改變敵人生命值的函數,然后我得到一個錯誤:

                  When I run the code I press a button that calls a function that changes the enemy health and then I get an error:

                  未定義全局名稱health_label"

                  不知何故,當調用 update_health 函數時,程序看不到在 init 中創建的 health_label 變量.

                  Somehow, when the update_health function is called, the program doesn't see the health_label variable that was created in the init.

                  推薦答案

                  需要使用bind方法,類似如下

                  You need to use the bind method, something like the following

                  health_label = Label(text=enemy.health)
                  self.enemyBar.add_widget(health_label)
                  def update_health(instance, value):
                      health_label.text = str(enemy.health)
                  enemy.bind(health=update_health)
                  

                  這只是我腦海中的一個基本示例,它可以根據您的程序結構變得更簡潔.如果enemy.health 是一個字符串,你可以這樣做 enemy.bind(health=health_label.setter('text')).

                  This is just a basic example off the top of my head, it can be made neater depending on the structure of your program. If enemy.health is a string, you can just do enemy.bind(health=health_label.setter('text')).

                  為此,health 屬性必須是 kivy 屬性:

                  For this to work, the health attribute must be a kivy property:

                  class Enemy(Something):
                      health = StringProperty('')
                  

                  在您的代碼中,敵人似乎是一個全局對象.很可能有更好的方法來做到這一點.另外,我建議使用 kv 語言 - 將代碼放在一個文件中并沒有任何特殊價值(事實上,一旦它變得不平凡,它通常被認為是不好的做法),并且 kv 使很多事情變得更容易,而 python 只是'不適合某些任務.

                  In your code it seems that enemy is a global object. There is quite likely a better way to do that. Also, I recommend using kv language - there is not really any special value in putting your code in one file (indeed, it's commonly considered bad practice once it gets non-trivial), and kv makes a lot of things easier where python just isn't suited to certain tasks.

                  這篇關于Kivy - 將標簽文本綁定到變量(僅限 Python)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)

                  <tfoot id='hs48T'></tfoot>
                • <legend id='hs48T'><style id='hs48T'><dir id='hs48T'><q id='hs48T'></q></dir></style></legend>
                  • <bdo id='hs48T'></bdo><ul id='hs48T'></ul>
                  • <small id='hs48T'></small><noframes id='hs48T'>

                      1. <i id='hs48T'><tr id='hs48T'><dt id='hs48T'><q id='hs48T'><span id='hs48T'><b id='hs48T'><form id='hs48T'><ins id='hs48T'></ins><ul id='hs48T'></ul><sub id='hs48T'></sub></form><legend id='hs48T'></legend><bdo id='hs48T'><pre id='hs48T'><center id='hs48T'></center></pre></bdo></b><th id='hs48T'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='hs48T'><tfoot id='hs48T'></tfoot><dl id='hs48T'><fieldset id='hs48T'></fieldset></dl></div>
                              <tbody id='hs48T'></tbody>
                            主站蜘蛛池模板: 日韩欧美三级电影在线观看 | 久久福利电影 | 成人av资源在线 | 亚洲精选久久 | 一区免费看 | 日韩在线中文 | 亚洲品质自拍视频网站 | 国产在线一区二区 | 中文字幕1区 | 久久久成人精品 | caoporn免费 | 国产91在线 | 亚洲 | 一级爱爱片 | 国产分类视频 | 国产亚洲成av人片在线观看桃 | 午夜精品网站 | 欧美日韩精品久久久免费观看 | 久久成人免费视频 | 久久成 | 美女在线观看av | 国产综合在线视频 | 99精品国自产在线 | 99精品免费在线观看 | 亚洲精品99 | 日韩在线成人 | av日韩高清 | 国产精品一区二区不卡 | 日韩精品久久久 | 中文字幕99 | 中文字幕在线播放第一页 | 欧美1—12sexvideos | 亚洲一区中文 | av在线一区二区三区 | 99久久免费精品国产免费高清 | 国产精品综合色区在线观看 | 精品久久久久久久久久久下田 | 欧美在线精品一区 | 亚洲国产伊人 | 亚洲成人一区二区 | 91久久精品一区二区二区 | 欧美一级黄色片在线观看 |