我在使用kivy时遇到了一些麻烦。我的目标是在textinput框旁边创建标签,以便人们记住他们应该输入的内容。我希望能够调整textinput框的大小,或者如果有更好的方法请告诉我!
<Phone>:
result: _result
h: _h
w: _w
AnchorLayout:
anchor_x: 'center'
anchor_y: 'top'
ScreenManager:
size_hint: 1, .9
id: _screen_manager
Screen:
name: 'home'
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: "/home/aaron/Desktop/main.png"
Label:
markup: True
text: '[size=50][color=ff3333]Welcome to [color=ff3333]Diabetes Manager[/color][/size]'
Screen:
name: 'menu'
GridLayout:
cols: 2
padding: 50
canvas.before:
Rectangle:
pos: self.pos
size: self.size
source: "/home/aaron/Desktop/main.png"
Button:
text: 'My Profile'
on_press: _screen_manager.current = 'profile'
Button:
text: 'History'
on_press: _screen_manager.current = 'history'
Button:
text: 'New Entry'
on_press: _screen_manager.current = 'new_entry'
Button:
text: 'Graph'
on_press: _screen_manager.current = 'graph'
Button:
text: 'Diet'
on_press: _screen_manager.current = 'diet'
Button:
text: 'Settings'
on_press: _screen_manager.current = 'settings'
Screen:
name: 'profile'
GridLayout:
rows: 1
BoxLayout:
Label:
text: 'Name'
TextInput:
id: _name
hint_text: 'Name'
Label:
text: 'Gender'
TextInput:
id: _gender1
hint_text: 'Gender'
Label:
text: 'Type of Diabetes'
TextInput:
id: _type
hint_text: 'Type of Diabetes'
Label:
text: 'Height(in)'
TextInput:
id: _h
hint_text: 'Height in inches'
Label:
text: 'Weight(lb)'
TextInput:
id: _w
hint_text: 'Weight in pounds'
Label:
id:_result
text: 'BMI'
Button:
text: 'Calculate BMI'
on_press: root.product(*args)
Label:
text: 'List of Medications'
TextInput:
id: _meds
hint_text: 'List of Medications'
Label:
text: 'Insulin Times'
TextInput:
id: _times
hint_text: 'Please Enter Times to Take Insulin'
Screen:
name: 'history'
GridLayout:
cols:1
Screen:
name: 'new_entry'
GridLayout:
cols:1
TextInput:
id: _time
text: 'Please Enter The Current Time'
TextInput:
id: _glucose_reading
text: 'Please Enter Your Current Blood Sugar'
TextInput:
id: _food
text: 'Please Enter Amount of Carbs for The Meal'
TextInput:
id: _meds_taken
text: 'Please Enter Any Medications Taken'
Screen:
name: 'graph'
GridLayout:
cols: 3
padding: 50
Label:
markup: True
text: '[size=24][color=dd88ff]Your Graph[/color][/size]'
Screen:
name: 'diet'
GridLayout:
cols: 3
padding: 50
Label:
markup: True
text: '[size=24][color=dd88ff]Reccomended Diet[/color][/size]'
Screen:
name: 'settings'
GridLayout:
cols: 3
padding: 50
Label:
markup: True
text: '[size=24][color=dd88ff]Settings[/color][/size]'
AnchorLayout:
anchor_x: 'center'
anchor_y: 'bottom'
BoxLayout:
orientation: 'horizontal'
size_hint: 1, .1
Button:
id: btnExit
text: 'Exit'
on_press: app.stop()
Button:
text: 'Menu'
on_press: _screen_manager.current = 'menu'
答案 0 :(得分:0)
您需要在GridLayout
内为每个TextInput
使用另一个布局,这将在内部创建一个包含两个小部件的小部件:Label和TextInput。结果将如下所示:
Screen:
name: 'profile'
GridLayout:
cols: 1
BoxLayout: ## Box 1
Label:
text: 'Name Please'
TextInput:
id: _name
BoxLayout: ## Box 2
Label:
text: 'Another Name Please'
TextInput:
id: _name
使用size_hint
,您可以在BoxLayout甚至BoxLayout本身中设置Label或TextInput的大小。
或者还有另一种方式 - hint_text,当TextInput为空时,会显示在其中。
示例:强>
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.uix.scrollview import ScrollView
Builder.load_string('''
<Test>:
GridLayout:
cols: 1
BoxLayout: ## here is one Box
Label:
text: 'Name Please'
TextInput:
BoxLayout: ## here is another Box
Label:
text: 'Name Please'
TextInput:
''')
class Test(ScrollView):pass
runTouchApp(Test())