在 ActionLabel 旁边放置一个 Kivy ActionCheck

Place a Kivy ActionCheck next to an ActionLabel

我面临的问题是在我的 ActionGroup 中包含一个复选框,旁边有一个标签。

在常规情况下,我会使用布局 class 来对齐小部件旁边的复选框。但是在 ActionView 或 ActionGroup 中,只允许 ActionItems 作为子项。

到目前为止,我尝试将 CheckBox 放入 ActionLabel 中,这导致了错误放置的透明背景 ActionItem (Checkbox above the ActionLabel):

ActionGroup:
id: view_menu_group
text: "[color=ff9900]View[/color]"
markup: True
mode: "spinner"

ActionLabel:
    text: "Compare Mode"
    ActionCheck:
        on_active: app.root.main_view.graph.multi_plot = self.active

我的目标应该与此类似:Menu Dropdown with Checkboxes

好的,这就是我们所做的:我们实际上可以在 ActionGroup 中放置任何类型的小部件或布局。出于某种原因,kivy 决定我们只有从 ActionItem 继承才能做到这一点。但是,基本上,代码是相同的:

from kivy.base import runTouchApp
from kivy.lang import Builder

runTouchApp(Builder.load_string('''
<MyCheckbox@BoxLayout+ActionItem>: # Inheritance in .kv
    ActionLabel:
        text: "Hello"
    ActionCheck:

ActionBar:
    size_hint: 1, 0.1 # REMOVE ME
    pos_hint: {'top':1} # REMOVE ME

    id: view_menu_group
    text: "[color=ff9900]View[/color]"
    markup: True
    mode: "spinner"

    ActionView:
        ActionPrevious:  # need this for some unknown reason
        ActionGroup:
            MyCheckbox:  # our custom Label+Checkbox ActionItem
'''))

外观如下: