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

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

    1. <legend id='lrxFv'><style id='lrxFv'><dir id='lrxFv'><q id='lrxFv'></q></dir></style></legend>
      • <bdo id='lrxFv'></bdo><ul id='lrxFv'></ul>

        在 Kivy for Python 中按下按鈕時更新標簽的文本

        Update label#39;s text when pressing a button in Kivy for Python(在 Kivy for Python 中按下按鈕時更新標簽的文本)
        <tfoot id='3wQJT'></tfoot>
        <legend id='3wQJT'><style id='3wQJT'><dir id='3wQJT'><q id='3wQJT'></q></dir></style></legend>

        <small id='3wQJT'></small><noframes id='3wQJT'>

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

                <tbody id='3wQJT'></tbody>

              • <bdo id='3wQJT'></bdo><ul id='3wQJT'></ul>

                1. 本文介紹了在 Kivy for Python 中按下按鈕時更新標簽的文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這是我的代碼:我想制作一個游戲,當您按下按鈕時,main_label 會更改文本,但我已經到處看了一個星期,但仍然不明白該怎么做.我查看了 Kivy 的網站,但我不明白.如您所見,我是 kivy 新手,經驗不足

                  Here is my code: I want to make a game where the main_label changes text when you press a button but I've looked everywhere for a week and still don't understand how to do it. I looked on Kivy's website but I don't understand. As you can see I'm new to kivy and not very experienced

                  from kivy.app import App
                  from kivy.uix.button import Button
                  from kivy.uix.label import Label
                  from kivy.uix.floatlayout import FloatLayout
                  from kivy.clock import Clock
                  
                  energy = 100
                  hours = 4
                  
                  class app1(App):
                      def build(self):
                          self.f = FloatLayout()
                  
                          #Labels
                          self.energy_label = Label(text = "Energy = " + str(energy), size_hint=(.1, .15),pos_hint={'x':.05, 'y':.9})
                          self.time_label = Label(text = "Hours = " + str(hours), size_hint=(.1, .15),pos_hint={'x':.9, 'y':.9})
                          self.name_label = Label(text = "Game", size_hint=(.1, .15),pos_hint={'x':.45, 'y':.9})
                          self.main_label = Label(text = "Default_text", size_hint=(1, .55),pos_hint={'x':0, 'y':.35})
                  
                          #Main Buttons
                          self.inventory_button = Button(text = "Inventory", size_hint=(.3, .1),pos_hint={'x':.65, 'y':.2})
                          self.help_button = Button(text = "Help", size_hint=(.3, .1),pos_hint={'x':.65, 'y':.1})
                          self.craft_button = Button(text = "Craft", size_hint=(.3, .1),pos_hint={'x':.05, 'y':.1})
                          self.food_button = Button(text = "Food", size_hint=(.3, .1),pos_hint={'x':.35, 'y':.2})
                          self.go_button = Button(text = "Go", size_hint=(.3, .1),pos_hint={'x':.35, 'y':.1})
                          self.walk_button = Button(text = "Walk", size_hint=(.3, .1),pos_hint={'x':.05, 'y':.2})
                  
                          def update(self, *args):
                              self.main_widget.text = str(self.current_text)
                  
                          self.f.add_widget(self.energy_label)
                          self.f.add_widget(self.main_label)
                          self.f.add_widget(self.time_label)
                          self.f.add_widget(self.inventory_button)
                          self.f.add_widget(self.help_button)
                          self.f.add_widget(self.craft_button)
                          self.f.add_widget(self.food_button)
                          self.f.add_widget(self.go_button)
                          self.f.add_widget(self.walk_button)
                          self.f.add_widget(self.name_label)
                          self.current_text = "Default"
                          Clock.schedule_interval(update, 1)
                          return self.f
                  
                  
                          def update_label(input):
                              input = self.current_text
                  
                          help_button.bind(on_press = update_label("success!"))
                  
                  
                  if __name__=="__main__":
                      app1().run()
                  

                  如何更新我的代碼,以便通過按下 help_button,main_label 更改其文本?

                  感謝您的幫助.

                  推薦答案

                  好吧!您的代碼確實需要改進.(我理解你沒有經驗.)

                  Well! there was a real need for improvement in your code. (I understand it as you are not experienced.)

                  改進:1

                  如果您在 build() 上返回一個小部件,或者您設置self.root.(你不應該在構建函數本身中制作所有的 gui.)

                  An application can be built if you return a widget on build(), or if you set self.root.(You shouldn't make all of the gui in build function itself.)

                  def build(self):
                      return Hello() #That's what is done here
                  

                  改進:2

                  on_release/on_press 兩者總是有用的.

                  on_release/on_press both are always useful.

                  self.help_button = Button(text = "Help", size_hint=(.3, .1),pos_hint={'x':.65, 'y':.1},on_press = self.update)
                  

                  改進:3

                  當 help_button 被按下時,更新函數被調用來改變 main_label 的文本.

                  As help_button is pressed, update function is called which changes the text of main_label.

                  def update(self,event):
                      self.main_label.text = "Changed to change"
                  

                  這是完整改進的代碼

                  from kivy.app import App
                  from kivy.uix.button import Button
                  from kivy.uix.label import Label
                  from kivy.uix.floatlayout import FloatLayout
                  from kivy.clock import Clock
                  
                  energy = 100
                  hours = 4
                  
                  class Hello(FloatLayout):
                      def __init__(self,**kwargs):
                          super(Hello,self).__init__(**kwargs)
                  
                          self.energy_label = Label(text = "Energy = " + str(energy), size_hint=(.1, .15),pos_hint={'x':.05, 'y':.9})
                          self.time_label = Label(text = "Hours = " + str(hours), size_hint=(.1, .15),pos_hint={'x':.9, 'y':.9})
                          self.name_label = Label(text = "Game", size_hint=(.1, .15),pos_hint={'x':.45, 'y':.9})
                          self.main_label = Label(text = "Default_text", size_hint=(1, .55),pos_hint={'x':0, 'y':.35})
                  
                      #Main Buttons
                          self.inventory_button = Button(text = "Inventory", size_hint=(.3, .1),pos_hint={'x':.65, 'y':.2})
                          self.help_button = Button(text = "Help", size_hint=(.3, .1),pos_hint={'x':.65, 'y':.1},on_press = self.update)
                          self.craft_button = Button(text = "Craft", size_hint=(.3, .1),pos_hint={'x':.05, 'y':.1})
                          self.food_button = Button(text = "Food", size_hint=(.3, .1),pos_hint={'x':.35, 'y':.2})
                          self.go_button = Button(text = "Go", size_hint=(.3, .1),pos_hint={'x':.35, 'y':.1})
                          self.walk_button = Button(text = "Walk", size_hint=(.3, .1),pos_hint={'x':.05, 'y':.2})
                  
                          self.add_widget(self.energy_label)
                          self.add_widget(self.main_label)
                          self.add_widget(self.time_label)
                          self.add_widget(self.inventory_button)
                          self.add_widget(self.help_button)
                          self.add_widget(self.craft_button)
                          self.add_widget(self.food_button)
                          self.add_widget(self.go_button)
                          self.add_widget(self.walk_button)
                          self.add_widget(self.name_label)
                          self.current_text = "Default"
                  
                      def update(self,event):
                          self.main_label.text = "Changed to change"
                  
                  class app1(App):
                      def build(self):
                          return Hello()
                  if __name__=="__main__":
                       app1().run()
                  

                  這篇關于在 Kivy for 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 - 自動更改角色顏色)
                        • <bdo id='r47Tv'></bdo><ul id='r47Tv'></ul>

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

                        • <small id='r47Tv'></small><noframes id='r47Tv'>

                              <tbody id='r47Tv'></tbody>

                            主站蜘蛛池模板: 91精品国产一二三 | 看av网 | 成人精品一区二区户外勾搭野战 | 中文字幕国产第一页 | 亚洲精品久久嫩草网站秘色 | 啪一啪| 成人三级网址 | 国产精品自拍视频网站 | 97精品一区二区 | 欧美亚洲视频 | 91精品国产综合久久久久 | 国产视频一区二区三区四区五区 | 亚洲欧美一区二区三区1000 | 国产小视频精品 | 中文字幕不卡 | 黄色片网此 | a级毛片免费高清视频 | 一级在线 | 久久精品免费一区二区三 | 欧美a级成人淫片免费看 | 国产成人精品免高潮在线观看 | 亚洲精品一| 久久国产精品一区二区 | 少妇特黄a一区二区三区88av | www.亚洲区 | a级在线免费 | 欧洲av一区 | 国产十日韩十欧美 | av喷水| 国产精品久久777777 | 国产免费观看久久黄av片涩av | 亚洲一区二区三区视频 | 国产9 9在线 | 中文 | 视频一二三区 | 日本成人免费观看 | 精品国产不卡一区二区三区 | 日韩欧美操| 欧美一区二区 | 伊久在线| 在线观看日本高清二区 | 狠狠色综合久久丁香婷婷 |