我无法弄清楚为什么复选框无法在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
答案 0 :(得分:1)
将您的kv
文件更改为:
BoxLayout:
size_hint_y: None
height: 200
orientation: 'horizontal'
CheckBox:
active: False
CheckBox:
active: True
然后CheckBox
es工作(至少对我而言)。之所以最有可能是因为明确指出了高度,我认为GridLayout
在设置height: self.minimum_height
时会有所期望。