我正在使用Python-2.7和kivy.Now我正在动态添加row
点击+添加更多按钮。
有人可以告诉我如何通过输入密钥添加行动态当enter
进入每个TextBox
的最后row
而不是新增的第一列上的+添加更多按钮和光标focus
时行?
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 StringProperty
Window.clearcolor = (0.5, 0.5, 0.5, 1)
Window.size = (500, 400)
class User(Screen):
def add_more(self):
self.ids.rows.add_row()
class Row(BoxLayout):
button_text = StringProperty("")
class Rows(BoxLayout):
row_count = 0
def __init__(self, **kwargs):
super(Rows, self).__init__(**kwargs)
self.add_row()
def add_row(self):
self.row_count += 1
self.add_widget(Row(button_text=str(self.row_count)))
class Test(App):
def build(self):
return self.root
if __name__ == '__main__':
Test().run()
<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:
id:test1
text: ' '
width: 300
multiline: False
on_text_validate: test2.focus = True
TextInput:
id:test2
text: ' '
width: 300
multiline: False
<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()
答案 0 :(得分:2)
TextInput:
id: test1
focus: True
text: ' '
width: 300
multiline: False
on_text_validate: test2.focus = True
TextInput:
id:test2
text: ' '
width: 300
multiline: False
on_text_validate: app.root.add_more()