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

    <i id='Su16J'><tr id='Su16J'><dt id='Su16J'><q id='Su16J'><span id='Su16J'><b id='Su16J'><form id='Su16J'><ins id='Su16J'></ins><ul id='Su16J'></ul><sub id='Su16J'></sub></form><legend id='Su16J'></legend><bdo id='Su16J'><pre id='Su16J'><center id='Su16J'></center></pre></bdo></b><th id='Su16J'></th></span></q></dt></tr></i><div id='Su16J'><tfoot id='Su16J'></tfoot><dl id='Su16J'><fieldset id='Su16J'></fieldset></dl></div>
  2. <legend id='Su16J'><style id='Su16J'><dir id='Su16J'><q id='Su16J'></q></dir></style></legend>
  3. <tfoot id='Su16J'></tfoot>

      如何让kivy复选框传递它的状态

      时间:2023-10-10

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

              <tbody id='vVr6q'></tbody>
          • <legend id='vVr6q'><style id='vVr6q'><dir id='vVr6q'><q id='vVr6q'></q></dir></style></legend>

                <bdo id='vVr6q'></bdo><ul id='vVr6q'></ul>
              • 本文介绍了如何让kivy复选框传递它的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                Main.py

                def if_active(self, state):
                    If state is true:
                        print "True"
                    else:
                        print "False"
                

                main.kv

                CheckBox
                    on_state: root.if_active(self.state)
                

                Ignoring all the classes and .run() and that stuff, It should be obvious what I'm trying to do here What am I doing wrong?

                解决方案

                The solution is as follow. Please refer to the example below for details.

                Snippets

                main.kv

                CheckBox:
                    on_active: root.if_active(self.active)
                

                main.py

                def if_active(self, state):
                    if state:
                        print "True"
                    else:
                        print "False"
                

                Example

                main.py

                from kivy.app import App
                from kivy.uix.boxlayout import BoxLayout
                from kivy.core.window import Window
                
                
                class CheckBoxDemo(BoxLayout):
                    def on_checkbox_active(self, value):
                        if value:
                            print("The checkbox is active because value={}".format(value))
                        else:
                            print("The checkbox is inactive because value={}".format(value))
                
                    def on_radiobutton_active(self, value):
                        if value:
                            print("The radiobutton is active because value={}".format(value))
                        else:
                            print("The radiobutton is inactive because value={}".format(value))
                
                
                class TestApp(App):
                    Window.size = (360, 360)
                    title = "Kivy Checkbox & RadioButton Demo"
                
                    def build(self):
                        return CheckBoxDemo()
                
                
                if __name__ == "__main__":
                    TestApp().run()
                

                test.kv

                #:kivy 1.10.0
                
                <CheckBoxDemo>:
                    orientation: "vertical"
                    Label:
                        size_hint: 1, 0.2
                        text: "Checkbox"
                
                    GridLayout:
                        cols: 2
                
                        CheckBox:
                            on_active: root.on_checkbox_active(self.active)
                        CheckBox:
                
                        CheckBox:
                            group: "radiobutton1"
                            on_active: root.on_radiobutton_active(self.active)
                        CheckBox:
                            group: "radiobutton1"
                            on_active: root.on_radiobutton_active(self.active)
                
                        CheckBox:
                            group: "radiobutton2"
                        CheckBox:
                            group: "radiobutton2"
                

                Output

                这篇关于如何让kivy复选框传递它的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Kivy:如何将复选框设置为在启动时选中 下一篇:将屏幕与 kivy 中的 GridLayout 类相关联

                相关文章

                最新文章

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

                  <bdo id='QeuwM'></bdo><ul id='QeuwM'></ul>
                <tfoot id='QeuwM'></tfoot>

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

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