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

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

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

    2. <tfoot id='ZpkZS'></tfoot>

      Kivy:如何将复选框设置为在启动时选中

      时间:2023-10-10
        <bdo id='9e34a'></bdo><ul id='9e34a'></ul>
          <tbody id='9e34a'></tbody>

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

              <legend id='9e34a'><style id='9e34a'><dir id='9e34a'><q id='9e34a'></q></dir></style></legend>

              <tfoot id='9e34a'></tfoot>
              • <small id='9e34a'></small><noframes id='9e34a'>

                本文介绍了Kivy:如何将复选框设置为在启动时选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                How can I set the status of the checkbox with the id set to blue to be checked on start up. I use python 3.6 and Kivy 1.9.2.dev0. I thought the lines blue = ObjectProperty(True) in .py and value: root.blue in .kv would do that but apparently I am misunderstanding how ObjectProperty works

                import kivy
                from kivy.app import App
                from kivy.uix.boxlayout import BoxLayout
                from kivy.properties import ObjectProperty
                from kivy.core.window import Window
                
                class SampBoxLayout(BoxLayout):
                
                    # For radio buttons
                    blue = ObjectProperty(True)
                    red = ObjectProperty(False)
                
                class SimpleApp(App):
                    def build(self):
                        Window.clearcolor = (1, 1, 1, 1)
                        return SampBoxLayout()
                
                sample_app = SimpleApp()
                sample_app.run()
                

                The .kv:

                #: import CheckBox kivy.uix.checkbox
                
                
                <SampBoxLayout>
                    orientation: "vertical"
                    padding: 10
                    spacing: 10
                    BoxLayout:
                        orientation: "horizontal"
                        size_hint_x: .55
                        Label:
                            text: "Favorite Color:"
                            color: 0, 0, 0, 1
                            size_hint_x: .265
                        Label:
                            text: "Blue"
                            color: 0, 0, 0, 1
                            size_hint_x: .15
                        CheckBox:
                            group: "fav_color"
                            id : blue
                            value: root.blue
                            size_hint_x: .05
                        Label:
                            text: "Red"
                            color: 0, 0, 0, 1
                            size_hint_x: .15
                        CheckBox:
                            group: "fav_color"
                            value: root.red
                            size_hint_x: .05
                

                Edit: why use value and not active?

                def on_checkbox_active(checkbox, value):
                    if value:
                        print('The checkbox', checkbox, 'is active')
                    else:
                        print('The checkbox', checkbox, 'is inactive')
                

                解决方案

                No you did not misunderstand it. You just used the wrong attribute name.
                Set the active attribute instead of value:

                from kivy.app import App
                from kivy.uix.boxlayout import BoxLayout
                from kivy.properties import ObjectProperty
                from kivy.lang import Builder
                
                
                root = Builder.load_string('''
                
                <MyWidget>:
                    CheckBox:
                        id: blue
                        active: root.blue
                    CheckBox:
                        id: red
                        active: root.red
                ''')
                
                class MyWidget(BoxLayout):
                    blue = ObjectProperty(True)
                    red = ObjectProperty(False)
                
                class MyApp(App):
                
                    def build(self):
                        return MyWidget()
                
                MyApp().run()
                

                这篇关于Kivy:如何将复选框设置为在启动时选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Kivy:如何在等待显示另一个小部件时显示一个小部 下一篇:如何让kivy复选框传递它的状态

                相关文章

                最新文章

                  <bdo id='AFhdx'></bdo><ul id='AFhdx'></ul>
              • <tfoot id='AFhdx'></tfoot>

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

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