【发布时间】:2017-12-31 14:32:05
【问题描述】:
谁能告诉我如何在这段代码中使用滚动条?其次,是否有任何方法可以对齐标签和 TextInput,以便 TextInput 中的文本无论有多少 Input 都将清晰可见。这里对齐意味着:如果有 100s(数百或数千)个 TextInputs ,则 TextInput 内的文本应该是正确可见的。实际上,当我在代码中给出一些(间距 = 50)时,在大约 20 秒的输入后,文本无法正常显示。 提前致谢。
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import StringProperty
from kivy.uix.textinput import TextInput
from kivy.uix.checkbox import CheckBox
from kivy.lang import Builder
ROWS = ['Goc', 'COC', 'EEE', 'abs' , 'kju' , 'iop' , 'nmg', 'gty', 'jkio', 'dbkgcd' , 'udbcbjkb']
Builder.load_string("""
<Test>:
do_default_tab: False
TabbedPanelItem:
text: 'page1'
Table:
padding: 50, 50, 50, 50
orientation: 'vertical'
<Row>:
spacing: 50
size_hint_x: 1
txt: txtinpt.text
Label:
text: root.txt
TextInput:
id: txtinpt
text: root.txt
disabled: not CheckBox.active
CheckBox:
id:CheckBox
text: 'CheckBox'
active: False
Button:
text: 'save'
""")
class Table(BoxLayout):
def __init__(self, **kwargs):
super(Table, self).__init__(**kwargs)
for row in ROWS:
self.add_widget(Row(row))
class Row(BoxLayout):
txt = StringProperty()
def __init__(self, row, **kwargs):
super(Row, self).__init__(**kwargs)
self.txt = row
class Test(TabbedPanel):
pass
class MyApp(App):
def build(self):
test = Test()
return test
if __name__ == '__main__':
MyApp().run()
【问题讨论】:
-
添加滚动视图很简单,但我不确定您所说的“对齐标签和 TextInput”是什么意思,您能举个例子或图片来说明您想要什么吗?
-
亲爱的@FJSevilla,会有成百上千行,所以我们应该通过滚动看到输入。
标签: python user-interface scrollview kivy