Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python/kivy:如何在.kv文件中传递来自另一个类的文本值_Python_Python 3.x_Python 2.7_Kivy_Kivy Language - Fatal编程技术网

python/kivy:如何在.kv文件中传递来自另一个类的文本值

python/kivy:如何在.kv文件中传递来自另一个类的文本值,python,python-3.x,python-2.7,kivy,kivy-language,Python,Python 3.x,Python 2.7,Kivy,Kivy Language,我有两个文件demo.py和demo.kv。当运行demo.py时,会显示3行。因为我正在从数据库获取数据。它的显示方式类似。 rows = [('test1', 'BAG1'), ('test2', 'BAG2'), ('test3', 'BAG3')] for row in rows: self.row_count += 1 self.add_widget(Row(button_text=str(self.row_count))) 重复3次,我的sreen看起来像 [![在

我有两个文件
demo.py
demo.kv
。当运行
demo.py
时,会显示3行。因为我正在从数据库获取数据。它的显示方式类似。

rows = [('test1', 'BAG1'), ('test2', 'BAG2'), ('test3', 'BAG3')]
for row in rows:
    self.row_count += 1
    self.add_widget(Row(button_text=str(self.row_count)))
重复3次,我的sreen看起来像 [![在此处输入图像描述][1][1]
现在我想在文本框中显示值,如

 Number name  value
    1.  test1 BAG1
    2.  test2 BAG2
    3.  test3 BAG3
有人能帮我从另一个类(
class Rows(BoxLayout):
)将值
root.colu数据[3]
root.colu数据[4]
传递到for循环中吗

demo.py 千伏
:
尺寸提示:无
高度:自身最小高度
身高:40
按钮:
文本:root.button\u文本
大小提示:无
排名:200
文本输入:
text:root.col_数据[3]
宽度:300
文本输入:
text:root.col_数据[4]
宽度:300
:
尺寸提示:无
高度:自身最小高度
方向:“垂直”
用户:
盒子布局:
方向:“垂直”
填充:20,5
盒子布局:
方向:“水平”
#填充:10,10
间距:10,10
尺寸:450,40
大小提示:无,无
标签:
大小\u提示\u x:.2
正文:“编号”
文本大小:self.size
valign:“底部”
哈利恩:“中心”
标签:
大小\u提示\u x:.4
正文:“姓名”
文本大小:self.size
valign:“底部”
哈利恩:“中心”
标签:
大小\u提示\u x:.4
正文:“价值”
文本大小:self.size
valign:“底部”
哈利恩:“中心”
滚动视图:
排:
id:行
盒子布局:
方向:“水平”
大小\u提示\u x:.2
大小\u提示\u y:.2
按钮:
正文:“+添加更多”
按:root.add\u more()
当您编写
Row()
时,您将创建Row的新实例。您希望创建它一次,然后修改它

更改
添加行
功能如下:

def add_row(self):
    #fetching from database
    rows = [('test1', 'BAG1'), ('test2', 'BAG2'), ('test3', 'BAG3')]
    for row in rows:
        self.row_count += 1
        r = Row(button_text=str(self.row_count))
        r.col_data[3] = row[0]
        r.col_data[4] = row[1]
        self.add_widget(r)
结果:

<Row>:
    size_hint_y: None
    height: self.minimum_height
    height: 40

    Button:
        text: root.button_text
        size_hint_x: None
        top: 200

    TextInput:
        text: root.col_data[3]
        width: 300
    TextInput:
        text: root.col_data[4]
        width: 300


<Rows>:
    size_hint_y: None
    height: self.minimum_height
    orientation: "vertical"

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


        BoxLayout:
            orientation: "horizontal"
            #padding : 10, 10
            spacing: 10, 10
            size: 450, 40
            size_hint: None, None

            Label:
                size_hint_x: .2
                text: "Number"
                text_size: self.size
                valign: 'bottom'
                halign: 'center'

            Label:
                size_hint_x: .4
                text: "name"
                text_size: self.size
                valign: 'bottom'
                halign: 'center'

            Label:
                size_hint_x: .4
                text: "Value"
                text_size: self.size
                valign: 'bottom'
                halign: 'center'




        ScrollView:
            Rows:
                id: rows


        BoxLayout:
            orientation: "horizontal"
            size_hint_x: .2
            size_hint_y: .2

            Button:
                text: "+Add More"
                on_press: root.add_more()
Row().col_data[3] = row[0]
Row().col_data[4] = row[1]
def add_row(self):
    #fetching from database
    rows = [('test1', 'BAG1'), ('test2', 'BAG2'), ('test3', 'BAG3')]
    for row in rows:
        self.row_count += 1
        r = Row(button_text=str(self.row_count))
        r.col_data[3] = row[0]
        r.col_data[4] = row[1]
        self.add_widget(r)