Python&Kivy - 显示/隐藏框

问题描述 投票:0回答:1

我构建了一个正在拍照的应用程序,然后转到另一个空白屏幕并在后台运行我的主代码。我想在空屏幕中显示一个文本输入框,而我的主代码处于第一个if条件;并在代码处于2nd条件时隐藏该框。我的代码在下面。对于我的问题,我为不必要的长事写了“blablabla”。

class CheckScreen(Screen):
    def deneme(self):

    #MY MAIN CODE
    #...

        if(BLABLABLA)
            self.isShownMenu = BooleanProperty(True)
        else
            self.isShownMenu = BooleanProperty(False)

GUI = Builder.load_string("""

#BLABLABLA1
#...

<SingleLineTextInput@TextInput>:
    pos_hint: {'center_x': .5, 'center_y': .4}
    size_hint: 0.5, 0.05
    multiline: False
<CheckScreen>:

    #BLABLABLA2
    #...

    SingleLineTextInput:
        opacity: 1 if root.isShownMenu else 0
""")

class TestCamera(App):

def build(self):
    return GUI

TestCamera().run()

当我运行这个时,app总是会显示textinput,即使我在条件下将True更改为False。我的问题在哪里?

python input kivy screen textinput
1个回答
0
投票

您的BooleanProperty需要在类级别定义:

class CheckScreen(Screen):
    isShownMenu = BooleanProperty(True)

根据需要使用TrueFalse。然后在你的代码中引用self.isShownMenu,如:

    if(BLABLABLA)
        self.isShownMenu = True
    else
        self.isShownMenu = False
© www.soinside.com 2019 - 2024. All rights reserved.