Python 2.7 Python/Kivy:按enter键在文本框中设置值

Python 2.7 Python/Kivy:按enter键在文本框中设置值,python-2.7,kivy,kivy-language,Python 2.7,Kivy,Kivy Language,我正在使用python-2.7和kivy。我正在使用Tree view进入动态添加行。label通过上下键选择。我正在尝试当按下enter键时,文本被复制到TextBox。有人能告诉我怎么做吗是吗 test.py 试验电压(千伏) : 字体大小:15 字体名称:“Verdana” : 字体大小:15 字体名称:“Verdana” 填充y:3 : 尺寸提示:无 高度:自身最小高度 身高:40 按钮: 文本:root.button\u文本 大小提示:无 排名:200 文本输入: 文本:“” 宽度:3

我正在使用
python-2.7
kivy
。我正在使用
Tree view
进入动态添加行。
label
通过上下键选择。我正在尝试当按下
enter
键时,文本被复制到
TextBox
。有人能告诉我怎么做吗是吗

test.py 试验电压(千伏)
:
字体大小:15
字体名称:“Verdana”
:
字体大小:15
字体名称:“Verdana”
填充y:3
:
尺寸提示:无
高度:自身最小高度
身高:40
按钮:
文本:root.button\u文本
大小提示:无
排名:200
文本输入:
文本:“”
宽度:300
多行:False
在文本上验证:test2.focus=True
on_focus:root.显示_组(self)
:
尺寸提示:无
高度:自身最小高度
方向:“垂直”
用户:
盒子布局:
方向:“垂直”
填充:20,5
滚动视图:
排:
id:行
盒子布局:
方向:“水平”
大小\u提示\u x:.2
大小\u提示\u y:.2
按钮:
正文:“+添加更多”
按:root.add\u more()
:
按下按钮时:
app.root.name.text=self.text
app.root.popup.disclose()文件
:
id:treeview
树视图:树视图
标题:“选择”
大小提示:无,无
尺寸:400200
自动解除:错误
盒子布局
方向:“垂直”
盒子布局:
id:treeview
按钮:
大小提示:1,0.1
正文:“结束”
发布时:root.disclose()

树视图组用于填充
文本输入
,因此它应该将该字段作为属性,从而访问该小部件并设置文本

class TreeviewGroup(Popup):
    treeview = ObjectProperty(None)
    tv = ObjectProperty(None)

    def __init__(self, text_input, **kwargs):
        super(TreeviewGroup, self).__init__(**kwargs)
        self.text_input = text_input # set property
        self.tv = TreeView(root_options=dict(text=""),
                       hide_root=False,
                       indent_level=4)
        ...

    def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
        ...
        elif key == 'enter':
            self.text_input.text = node.text # set text
            keyboard.release()
            self.dismiss()


...
class Row(BoxLayout):
    button_text = StringProperty("")
    popup = ObjectProperty(None)

    def display_groups(self, instance, value):
        if len(instance.text) > 0 and value:
            if self.popup is None:
                self.popup = TreeviewGroup(instance) # pass TextInput
            self.popup.open()
<Button@Button>:
    font_size: 15
    font_name: 'Verdana'


<TextInput@TextInput>:
    font_size: 15
    font_name: 'Verdana'
    padding_y: 3


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

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

    TextInput:
        text: ' '
        width: 300
        multiline: False
        on_text_validate: test2.focus = True
        on_focus: root.display_groups(self)


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

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

        ScrollView:
            Rows:
                id: rows


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

            Button:
                text: "+Add More"
                on_press: root.add_more()

<TreeViewLabel>:
    on_touch_down:
        app.root.name.text = self.text
        app.root.popup.dismiss()

<TreeviewGroup>:
    id: treeview
    treeview: treeview
    title: "Select"
    size_hint: None, None
    size: 400, 200
    auto_dismiss: False

    BoxLayout
        orientation: "vertical"

        BoxLayout:
            id: treeview
        Button:
            size_hint: 1, 0.1
            text: "Close"
            on_release: root.dismiss()
class TreeviewGroup(Popup):
    treeview = ObjectProperty(None)
    tv = ObjectProperty(None)

    def __init__(self, text_input, **kwargs):
        super(TreeviewGroup, self).__init__(**kwargs)
        self.text_input = text_input # set property
        self.tv = TreeView(root_options=dict(text=""),
                       hide_root=False,
                       indent_level=4)
        ...

    def _on_keyboard_down(self, keyboard, keycode, text, modifiers):
        ...
        elif key == 'enter':
            self.text_input.text = node.text # set text
            keyboard.release()
            self.dismiss()


...
class Row(BoxLayout):
    button_text = StringProperty("")
    popup = ObjectProperty(None)

    def display_groups(self, instance, value):
        if len(instance.text) > 0 and value:
            if self.popup is None:
                self.popup = TreeviewGroup(instance) # pass TextInput
            self.popup.open()