Python / Kivy:使用python删除空间

时间:2018-08-11 09:23:57

标签: python python-2.7 kivy kivy-language

我正在使用python-2.7kivy。我正在尝试用空格隐藏TextInput。

这时我正在使用opacity属性来隐藏Textinput

self.row.abc.opacity = 0

使用此代码,TextInput隐藏,但未删除空格。有人可以告诉我如何删除空格或其他更好的解决方案,以使用空格隐藏Textinput。

test.py

from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import ListProperty, StringProperty, ObjectProperty

Window.size = (450, 425)


class display(Screen):

    def __init__(self, **kwargs):
        super(display, self).__init__(**kwargs)

    def add_more(self):
        self.ids.rows.add_row()

class Row(BoxLayout):
    button_text = StringProperty("")
    id = ObjectProperty(None)
    col_data = ListProperty(["", ""])



class Rows(BoxLayout):
    orientation = "vertical"
    row_count = 0

    def __init__(self, **kwargs):
        super(Rows, self).__init__(**kwargs)
        self.add_row()

    def add_row(self):
        self.row_count += 1
        self.row = Row(button_text=str(self.row_count))
        self.row.abc.opacity = 0
        self.row.col_data[1] = 'Test1'
        self.add_widget(self.row)


class test(App):

    def build(self):
        return self.root

if __name__ == '__main__':
    test().run()

test.kv

<Row>:
    abc: abc
    #state1 : state1
    orientation: "horizontal"
    spacing: 0, 5

    Button:
        text: root.button_text
        size_hint_x: .2

    TextInput:
        id : abc
        size_hint_x: .8
        text : root.col_data[0]

    TextInput:
        size_hint_x: .8
        text : root.col_data[1]

display:

    BoxLayout:
        orientation: "vertical"
        padding : 20, 20

        BoxLayout:
            orientation: "horizontal"

            Button:
                size_hint_x: .2
                text: "+Add More"
                valign: 'bottom'
                on_press: root.add_more()


        BoxLayout:
            orientation: "horizontal"

            Label:
                size_hint_x: .2
                text: "SN"
                valign: 'bottom'

            Label:
                size_hint_x: .8
                text: "Value1"
                valign: 'bottom'

            Label:
                size_hint_x: .8
                text: "Value2"
                valign: 'bottom'


        Rows:
            id: rows

0 个答案:

没有答案