我正在尝试使用一些菜单切换按钮创建屏幕,然后创建一个嵌套的屏幕管理器,我只能在容器内切换屏幕管理器,并保持容器外的菜单不变。当我使用Boxlayouts和Gridlayouts的组合时,一切都在彼此之中。
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.graphics.context_instructions import Color
from kivy.uix.screenmanager import Screen, ScreenManager
class ScreenManagement(FloatLayout):
pass
class IomApp(App):
def build(self):
return ScreenManagement()
if __name__ == '__main__':
IomApp().run()
Kivy档案:
<LabelCases@Label>:
height: '40dp'
font_size: 18
<TextInputCases@TextInput>:
height: '40dp'
size_hint_y: None
font_size: 18
write_tab: False
multiline: False
on_text_validate: root.foo()
<ScreenManagement>:
BoxLayout:
orientation: "vertical"
BoxLayout:
height: "80dp"
size_hint_y: None
Label:
text: 'Patient info Label'
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'vertical'
size_hint_x: 20
ToggleButton:
text: 'Case Info'
group: 'g1'
on_screen:
ToggleButton:
text: 'Modalities'
group: 'g1'
ToggleButton:
text: 'Report Editing'
group: 'g1'
ToggleButton:
text: 'Printing/Exporting'
group: 'g1'
ToggleButton:
text: 'Settings'
group: 'g1'
BoxLayout:
orientation: 'vertical'
size_hint_x: 80
ScreenManager:
id: "Screen1"
Screen:
name: "Case_info_screen"
BoxLayout:
orientation: 'vertical'
spacing: 20
orientation: 'vertical'
size_hint: (.5, .5)
pos_hint: {'center_x':.5, 'center_y':.5}
Label:
text: "Case Info"
size_hint_y: 25
GridLayout:
cols: 2
padding: 50
spacing: 15
size_hint_y: 50
LabelCases:
text: 'First Name: '
TextInputCases:
LabelCases:
text: 'Last Name: '
TextInputCases:
LabelCases:
text: 'MRN: '
TextInputCases:
LabelCases:
text: 'Date of Birth: '
TextInputCases:
LabelCases:
text: 'Hospital: '
TextInputCases:
LabelCases:
text: 'Diagnosis: '
TextInputCases:
Label:
text: "Surgical and Techical Staff"
size_hint_y: 25
BoxLayout:
Button:
height: "40dp"
size_hint_y: None
text: "Back"
Button:
height: "40dp"
size_hint_y: None
text: "Next"
答案 0 :(得分:0)
您已经使用了布局,但即使您使布局的大小相对于其子级的大小为 fixed / static (height: '40dp'
)。如果您从size_hint_y: None
移除TextInputCases
,则会看到有什么问题。
你的代码
<LabelCases@Label>:
font_size: 18
<TextInputCases@TextInput>:
font_size: 18
write_tab: False
multiline: False
on_text_validate: root.foo()
<ScreenManagement>:
BoxLayout:
orientation: "vertical"
BoxLayout:
height: "80dp"
size_hint_y: None
Label:
text: 'Patient info Label'
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'vertical'
size_hint_x: .20
ToggleButton:
text: 'Case Info'
group: 'g1'
on_screen:
ToggleButton:
text: 'Modalities'
group: 'g1'
ToggleButton:
text: 'Report Editing'
group: 'g1'
ToggleButton:
text: 'Printing/Exporting'
group: 'g1'
ToggleButton:
text: 'Settings'
group: 'g1'
BoxLayout:
orientation: 'vertical'
size_hint_x: .80
ScreenManager:
id: "Screen1"
Screen:
name: "Case_info_screen"
BoxLayout:
orientation: 'vertical'
spacing: 20
orientation: 'vertical'
size_hint: (.5, .8)
pos_hint: {'center_x':.5, 'center_y':.5}
Label:
text: "Case Info"
size_hint_y: .25
GridLayout:
cols: 2
padding: 50
spacing: 15
size_hint_y: .70
LabelCases:
text: 'First Name: '
TextInputCases:
LabelCases:
text: 'Last Name: '
TextInputCases:
LabelCases:
text: 'MRN: '
TextInputCases:
LabelCases:
text: 'Date of Birth: '
TextInputCases:
LabelCases:
text: 'Hospital: '
TextInputCases:
LabelCases:
text: 'Diagnosis: '
TextInputCases:
Label:
text: "Surgical and Techical Staff"
BoxLayout:
height: "40dp"
size_hint_y: None
Button:
text: "Back"
Button:
text: "Next"
但我宁愿推荐像ScrollView这样的东西 - &gt; GridLayout - &gt;所有孩子,这样你就可以拥有固定大小的内容(具有滚动功能)并保留“iframe”般的布局。 ^^