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

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

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

      2. 如何獲取 kivy 按鈕的 Id 和 Text 值作為字符串?

        How to get Id and Text value of a kivy button as string?(如何獲取 kivy 按鈕的 Id 和 Text 值作為字符串?)

          <bdo id='mOrDn'></bdo><ul id='mOrDn'></ul>

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

                  本文介紹了如何獲取 kivy 按鈕的 Id 和 Text 值作為字符串?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個帶有多個按鈕的應用程序,我需要在按下按鈕時將按鈕的 id 和文本值作為字符串獲取.然后將抓取的按鈕的 Ids 和 Text 值傳遞給另一個函數以進行進一步處理.為簡單起見,我編寫了這個示例程序.

                  I have an app with multiple buttons and I need to get id and text value of the button as string when it is pressed. The grabbed Ids and Text valus of the button will then be passed to another function for further processing. For simplicity I wrote this sample programme.

                  # main.py
                  
                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  
                  ########################################################################
                  class KVMyHBoxLayout(BoxLayout):
                      pass
                  
                  
                  ########################################################################
                  class ExampleApp(App):
                      def Pressbtn(self, *args):
                          print'Pressed button'
                      #----------------------------------------------------------------------
                      def build(self):
                  
                          return KVMyHBoxLayout()
                  
                  #----------------------------------------------------------------------
                  if __name__ == "__main__":
                      app = ExampleApp()
                      app.run()
                  

                  kv文件

                  <MyButton@Button>:
                      color: .8,.9,0,1
                      font_size: 32
                  
                  <KVMyHBoxLayout>:
                      orientation: 'vertical'
                      MyButton:
                          id:"idBtn1"
                          text: "Btn1"
                          background_color: 1,0,0,1
                          on_press:app.Pressbtn()
                      MyButton:
                          id:"idBtn2"
                          text: "Btn2"
                          background_color: 0,1,0,1
                          on_press:app.Pressbtn()
                      Label:
                          text: "ID"
                          background_color: 0,0,1,1
                      Label:
                          text: "Text"
                          background_color: 1,0,1,1
                  

                  當按下按鈕時,其對應的 id 和 text 值將顯示在 ID 和 Text 標簽中.目前上述代碼僅在按下按鈕時打印Pressed button.我想知道如何以python方式獲取按鈕的id和文本值.

                  When a button is pressed its corresponding values of id and text will be shown in the ID and Text labels. Currently the above code only print Pressed button when button is pressed. I want to know how to get id and text value of button pythonically.

                  推薦答案

                  首先,從kv調用時,必須將按鈕實例顯式傳遞給方法:

                  First, you must pass the button instance explicitly to the method when it is called from the kv:

                  on_press: app.Pressbtn(self)
                  

                  然后您可以使用實例引用來修改按鈕或查看其屬性,您不需要 id.如果要獲取id,只能使用按鈕父級的ids字典.

                  You can then use the instance reference to modify the button or see its attributes, you do not need the id. If you want to get the id, you can only do it using the ids dictionary of the button parent.

                  基于您的代碼的示例:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.lang import Builder
                  
                  kv_file = '''
                  <MyButton@Button>:
                      color: .8,.9,0,1
                      font_size: 32
                  
                  <KVMyHBoxLayout>:
                      orientation: 'vertical'
                      MyButton:
                          id:"idBtn1"
                          text: "Btn1"
                          background_color: 1,0,0,1
                          on_press:app.Pressbtn(self)
                      MyButton:
                          id:"idBtn2"
                          text: "Btn2"
                          background_color: 0,1,0,1
                          on_press:app.Pressbtn(self)
                      Label:
                          id: lobj
                          text: "Object"
                          background_color: 1,0,1,1
                  
                      Label:
                          id: lid
                          text: "ID"
                          background_color: 0,0,1,1
                      Label:
                          id: ltext
                          text: "Text"
                          background_color: 1,0,1,1
                  '''
                  
                  
                  class KVMyHBoxLayout(BoxLayout):
                      pass
                  
                  class ExampleApp(App):
                      def Pressbtn(self, instance):
                          instance.parent.ids.lobj.text = str(instance)
                          instance.parent.ids.ltext.text = instance.text
                          instance.parent.ids.lid.text= self.get_id(instance)
                  
                      def get_id(self,  instance):
                          for id, widget in instance.parent.ids.items():
                              if widget.__self__ == instance:
                                  return id
                  
                      def build(self):
                          Builder.load_string(kv_file)
                          return KVMyHBoxLayout()
                  
                  if __name__ == "__main__":
                      app = ExampleApp()
                      app.run()
                  

                  輸出:

                  如果您在 .py 文件中定義小部件(按鈕),則無需將實例傳遞給函數,它會自動作為參數傳遞:

                  If you define the widget (button) in the .py file you do not need to pass the instance to the function, it is passed automatically as argument:

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  from kivy.uix.button import Button
                  from kivy.uix.scrollview import ScrollView
                  
                  
                  class FirstScreen(Screen):
                      def __init__(self,**kwargs):
                          super(FirstScreen, self).__init__(**kwargs)    
                          layout=BoxLayout(orientation="vertical",size_hint_y= None)
                          layout.bind(minimum_height=layout.setter('height'))                
                          for i in range(50):
                                  btn = Button(text="Button"+str(i),
                                               id=str(i),
                                               size_hint=(None, None),
                                               on_press=self.Press_auth)               #<<<<<<<<<<<<<<<<           
                                  layout.add_widget(btn)
                          root = ScrollView()
                          root.add_widget(layout)
                          self.add_widget(root)
                  
                      def Press_auth(self,instance):     
                          print(str(instance))
                  
                  class TestScreenManager(ScreenManager):
                      def __init__(self,  **kwargs):
                          super(TestScreenManager,  self).__init__(**kwargs)
                          self.add_widget(FirstScreen())
                  
                  class ExampleApp(App):
                      def build(self):           
                          return TestScreenManager()
                  
                  def main():
                      app = ExampleApp()
                      app.run()
                  
                  if __name__ == '__main__':
                      main()
                  

                  這篇關于如何獲取 kivy 按鈕的 Id 和 Text 值作為字符串?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)
                      <tbody id='rNH4Y'></tbody>
                    <tfoot id='rNH4Y'></tfoot>
                  1. <i id='rNH4Y'><tr id='rNH4Y'><dt id='rNH4Y'><q id='rNH4Y'><span id='rNH4Y'><b id='rNH4Y'><form id='rNH4Y'><ins id='rNH4Y'></ins><ul id='rNH4Y'></ul><sub id='rNH4Y'></sub></form><legend id='rNH4Y'></legend><bdo id='rNH4Y'><pre id='rNH4Y'><center id='rNH4Y'></center></pre></bdo></b><th id='rNH4Y'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rNH4Y'><tfoot id='rNH4Y'></tfoot><dl id='rNH4Y'><fieldset id='rNH4Y'></fieldset></dl></div>

                  2. <small id='rNH4Y'></small><noframes id='rNH4Y'>

                      <bdo id='rNH4Y'></bdo><ul id='rNH4Y'></ul>

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

                          • 主站蜘蛛池模板: 亚洲视频三| 久久成人一区 | 色视频在线播放 | caoporn国产| av一区在线观看 | 日韩久久久久久 | 欧美www在线观看 | 久久婷婷麻豆国产91天堂 | 亚洲视频免费在线观看 | 久热久草| а天堂中文最新一区二区三区 | 久久国产一区二区三区 | 亚洲三级在线 | 国产成人99久久亚洲综合精品 | a黄视频| 国产欧美一区二区三区久久手机版 | 成人妇女免费播放久久久 | 国产一区二区观看 | 午夜视频导航 | 国产精品一区二区免费 | 亚洲综合第一页 | 精品久久久久久 | 日韩不卡一区二区 | 亚洲第一女人av | av黄色国产 | 久久久久久成人 | 蜜桃五月天| 国产午夜精品一区二区三区嫩草 | 成人精品系列 | 99精品网站| 亚洲最新网址 | 久久国产综合 | 欧美在线一区二区三区 | 亚洲国产精久久久久久久 | 91.色 | 日日夜夜免费精品 | 国产一级网站 | 福利二区| 欧美激情综合色综合啪啪五月 | 中文字幕在线观看 | 日韩欧美在线视频 |