<tfoot id='mJxc3'></tfoot>

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

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

  • <legend id='mJxc3'><style id='mJxc3'><dir id='mJxc3'><q id='mJxc3'></q></dir></style></legend>

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

        在 python 端的 kivy 中分配 id

        时间:2023-10-10

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

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

            <tfoot id='rTkDr'></tfoot>

              <bdo id='rTkDr'></bdo><ul id='rTkDr'></ul>
                1. <legend id='rTkDr'><style id='rTkDr'><dir id='rTkDr'><q id='rTkDr'></q></dir></style></legend>
                    <tbody id='rTkDr'></tbody>
                  本文介绍了在 python 端的 kivy 中分配 id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 kivy.我想做的是拥有和想法",一个滑块和一个标签,该标签在网格布局中的一行中包含滑块的当前值

                  im using kivy. the what im trying to do is have and 'idea',a slider and a label containing the slider's current value in a row in a grid layout

                  现在获得布局很好,但让标签具有与滑块当前值相同的文本值是棘手的.我正在尝试使用字符串连接来引用与它配对的滑块具有相同数字后缀的标签.

                  now getting the layout is fine but getting the label to have a text value the same as the slider's current value is tricky. I'm trying to use string concation to refer to the label with the same number suffix as the slider that it is paired with.

                  我认为我遇到的问题是,当通常必须在 kv 端完成时,我试图在 python 端分配 id.当 kv 通常期望纯文本时,要么就是我分配的 id 是字符串,要么是事实.任何帮助将不胜感激

                  I think the problem im having is that im trying to assign ids on the python side when they normally have to be done on the kv side. It's either that or the fact the ids i'm assigning are strings when kv would normally expect plain text. any help would be appreciated

                  class ScatterTextWidget(FloatLayout):
                          def run_me(self):
                              r=1 
                              main_list=self.ids.main_list
                              main_list.clear_widgets()
                              main_list.height=0
                              for idea in imported_ideas:     
                                  main_list.add_widget(Label(text=idea,color=(0,0,0,1),id='idea_label_'+str(r)))
                                  main_list.add_widget(Slider(id='Slider_'+str(r),min=0,max=10,value=5, step=1,on_value_pos=self.slider_slid(self)))
                                  main_list.add_widget(Label(color=(0,0,0,1),id='value_label_'+str(r)))
                  
                                  value_label=self.ids['value_label_'+str(r)] # get this working and then apply the method into slider slid
                                  value_label.text='xxx'
                  
                                  main_list.height+=35                
                  
                                  r +=1
                              button_1=self.ids.button_1
                              button_1.text='Begin'
                              button_1.bind(on_press=self.begin)
                  
                          def slider_slid(self,sender):
                  
                              s=str(sender.id)
                  
                              value_label=self.ids['value_label_'+str(s[12:])]
                              value_label.text=str(sender.value)
                  

                  value_label=self.ids['value_label_'+str(s[12:])]KeyError:'value_label_'

                  value_label=self.ids['value_label_'+str(s[12:])] KeyError: 'value_label_'

                  推荐答案

                  self.ids 在widget的kv语言规则中只收集children的id.它不知道您通过 python 添加的小部件.

                  self.ids only collects ids from children in the kv language rule of the widget. It doesn't know about widgets you added via python.

                  不过,您不需要使用 id.在这种情况下,您可以保留例如id -> 小部件键的字典.

                  You don't need to use the id though. In this case you could keep e.g. a dictionary of id -> widget keys.

                  self.keys_dict = {}
                  for idea in imported_ideas:     
                      new_widget = Label(color=(0,0,0,1),id='value_label_'+str(r)))
                      main_list.add_widget(new_widget)
                      self.keys_dict['value_label_' + str(r)] = new_widget
                  

                  然后您可以使用 self.keys_dict['value_label_' + str(s[12:])] 或任何您喜欢的方式访问它.

                  Then later you can access it with self.keys_dict['value_label_' + str(s[12:])] or whatever you like.

                  我想在实践中您也可以以相同的方式修改实际的 ids 字典,尽管我主观上认为最好使用代表其更具体内容的名称来维护您自己的字典.

                  I suppose in practice you could also modify the actual ids dictionary in the same way, though I subjectively feel it is preferable to maintain your own dictionary with a name that represents its more specific contents.

                  这篇关于在 python 端的 kivy 中分配 id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:PyInstalled Kivy 应用程序无法在第二台机器上运行 下一篇:向 Windows 添加“DEBUG=1"命令?

                  相关文章

                  最新文章

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

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