Kivy 复选框在 ScrollView 中不起作用
Kivy checkboxes don't work in ScrollView
我不明白为什么复选框在 ScrollView
中不起作用。以下代码和 .kv 文件不允许单击复选框,除非我删除 ScrollView
.
from kivy.app import App
from kivy.uix.screenmanager import (ScreenManager, Screen)
from kivy.uix.scrollview import ScrollView
class MainManager(ScreenManager):
pass
class Scrolling(ScrollView):
pass
class LoginScreen(Screen):
pass
class QuestionApp(App):
def build(self):
AppSM = MainManager()
AppSM.add_widget(LoginScreen(name='login'))
return AppSM
if __name__ == '__main__':
QuestionApp().run()
和 .kv 文件
<LoginScreen>:
Scrolling:
GridLayout:
cols: 1
padding: 15
spacing: 50
size_hint_y: None
height: self.minimum_height
Button:
size_hint_y: None
height: '200sp'
BoxLayout:
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
<Scrolling>:
do_scroll_x: False
bar_margin: 0
bar_width: 15
bar_color: [.7,.7,.7,.9]
bar_inactive_color: [.7,.7,.7,.9]
scroll_type: ['bars','content']
如果我将 <LoginScreen>:
更改为以下内容,删除滚动,复选框工作正常:
<LoginScreen>:
GridLayout:
cols: 1
padding: 15
spacing: 50
Button:
size_hint_y: None
height: '200sp'
BoxLayout:
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
将您的 kv
文件更改为:
BoxLayout:
size_hint_y: None
height: 200
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
然后 CheckBox
es 工作(至少对我来说)。原因很可能是因为明确规定的高度,我认为 GridLayout
在您设置 height: self.minimum_height
.
时期望的高度
我不明白为什么复选框在 ScrollView
中不起作用。以下代码和 .kv 文件不允许单击复选框,除非我删除 ScrollView
.
from kivy.app import App
from kivy.uix.screenmanager import (ScreenManager, Screen)
from kivy.uix.scrollview import ScrollView
class MainManager(ScreenManager):
pass
class Scrolling(ScrollView):
pass
class LoginScreen(Screen):
pass
class QuestionApp(App):
def build(self):
AppSM = MainManager()
AppSM.add_widget(LoginScreen(name='login'))
return AppSM
if __name__ == '__main__':
QuestionApp().run()
和 .kv 文件
<LoginScreen>:
Scrolling:
GridLayout:
cols: 1
padding: 15
spacing: 50
size_hint_y: None
height: self.minimum_height
Button:
size_hint_y: None
height: '200sp'
BoxLayout:
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
<Scrolling>:
do_scroll_x: False
bar_margin: 0
bar_width: 15
bar_color: [.7,.7,.7,.9]
bar_inactive_color: [.7,.7,.7,.9]
scroll_type: ['bars','content']
如果我将 <LoginScreen>:
更改为以下内容,删除滚动,复选框工作正常:
<LoginScreen>:
GridLayout:
cols: 1
padding: 15
spacing: 50
Button:
size_hint_y: None
height: '200sp'
BoxLayout:
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
将您的 kv
文件更改为:
BoxLayout:
size_hint_y: None
height: 200
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
然后 CheckBox
es 工作(至少对我来说)。原因很可能是因为明确规定的高度,我认为 GridLayout
在您设置 height: self.minimum_height
.