0

我正在尝试在浮动布局区域中创建一个复选框。我正在生成复选框,但每次单击它都会从 True 变为 False,即使它不在框中。有人可以提供一些见解吗?

我的代码:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.checkbox import CheckBox
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget


#######``Windows``#######
class MainScreen(Screen):
    pass

class AnotherScreen(Screen):
    def add(self, *args):
        a = self.ids["a"].text
        a = int(a)
        self.ids["adds"]
        plus = 1 + a
        print plus

class ScreenManagement(ScreenManager):
    pass


presentation = Builder.load_file("GUI_Style.kv")

class MainApp(App):
    def build(self):
        return presentation

if __name__ == "__main__":
    MainApp().run()

我的 KV 文件:

#: import NoTransition kivy.uix.screenmanager.NoTransition

ScreenManagement:
    transition: NoTransition()
    MainScreen:
    AnotherScreen:

<MainScreen>:
    background_color: 0.5, 1, 0.22, 1
    name: "main"
    FloatLayout:
        Button:
            text: "Quit"
            font_size: 50
            color: 0,1,0,1
            font_size: 25
            size_hint: 0.3,0.2
            pos_hint: {"x":0, "y":0}
            on_release: app.window().stop()
        Button:
            on_release: app.root.current = "other"
            text: "Next Screen"
            font_size: 50
            color: 0,1,0,1
            font_size: 25
            size_hint: 0.3,0.2
            pos_hint: {"right":1, "top":1}

<AnotherScreen>:
    name: "other"
    canvas.before:
        Color:
            rgba: 1, 1, 1, 1
        Rectangle:
            pos: self.pos
            size: self.size
    FloatLayout:
        CheckBox:
            pos_hint: {"x":0.2, "y":0.2}
            on_release: True
        TextInput:
            id: a
            font_size: 25
            password: True
            pos_hint: {"x":0.5, "y":0.5}
            size_hint: 0.3,0.2
            text: "Insert Side A here"
        Button:
            id: adds
            background_color: 0,0,1,1
            color: 0,1,0,1
            font_size: 25
            on_release: root.add()
            pos_hint: {"x":0, "y":0}
            size_hint: 0.3,0.2
            text: "plus"
        Button:
            color: 0,1,0,1
            background_color: 0,0,1,1
            font_size: 25
            size_hint: 0.3,0.2
            text: "Back Home"
            on_release: app.root.current = "main"
            pos_hint: {"right":1, "top":1}
4

1 回答 1

0

尝试将 CheckBox 放在小部件中,它可以工作。我是说:

FloatLayout:
    Widget:
        CheckBox:
            pos_hint: {"x":0.2, "y":0.2}
            on_release: True
    TextInput:
        id: a
        font_size: 25
        password: True
        pos_hint: {"x":0.5, "y":0.5}
        size_hint: 0.3,0.2
        text: "Insert Side A here"
    Button:
        id: adds
        background_color: 0,0,1,1
        color: 0,1,0,1
        font_size: 25
        on_release: root.add()
        pos_hint: {"x":0, "y":0}
        size_hint: 0.3,0.2
        text: "plus"

当然它会破坏您的布局,但它可以解决您遇到的问题。

于 2016-09-06T01:57:53.477 回答