gpt4 book ai didi

python - 如何使 Kivy 屏幕的一部分可滚动

转载 作者:太空宇宙 更新时间:2023-11-04 05:24:51 25 4
gpt4 key购买 nike

我正在寻找使用以下格式的 Kivy 库在 Python 中制作一个页面

    ________________________
| |
| title |
|______________________|
>>| Example 1 |<<
|______________________|
| | |
|___________|__________|
| | |
|___________|__________|
| | |
>>|___________|__________|<<
| Home |
|______________________|
| Settings |
|______________________|

箭头之间的屏幕部分应该是可滚动的。到目前为止,我拥有的代码如下:

Kv文件:

<ExampleScreen>:
BoxLayout:
orientation: 'vertical'
Label:
text: 'title'
ScrollView:
GridLayout:
cols: 1
Label:
text: 'Example 1'
GridLayout:
cols: 2
rows: 4
Label:
text: 'Filler'
Label:
text: 'Filler'
Label:
text: 'Filler'
Label:
text: 'Filler'
Label:
text: 'Filler'
Label:
text: 'Filler'
Label:
text: 'Filler'
Label:
text: 'Filler'
Button:
text: 'Home'
size_hint: 1, .1
on_press: root.manager.current = 'home'
Button:
text: 'Settings'
size_hint: 1, .1
on_press: root.manager.current = 'settings'

Py文件:

from kivy.uix.gridlayout import GridLayout
from kivy.uix.scrollview import ScrollView
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.lang import Builder

Builder.load_file('example.kv')

class ExampleScreen(Screen):
pass

sm = ScreenManager()

sm.add_widget(ExampleScreen(name = 'example'))

class TestApp(App):
def build(self):
return sm

if __name__ == '__main__':
TestApp().run()

我已经尝试了几种实现方法,但没有任何效果。有没有其他人对此有经验/知道这是否可能?感谢您的帮助!

最佳答案

是的,如果您的缩进和大小提示正确,这是可能的。
ScrollView doc

试试这个:

<MyLabel@Label>:
size_hint:1,None

<ExampleScreen>:
BoxLayout:
orientation: 'vertical'
Label:
text: 'title'
ScrollView:
size_hint: 1,None
GridLayout:
size_hint: 1,None
height: self.minimum_height
cols: 1
MyLabel:
text: 'Example 1'
GridLayout:
size_hint: 1,None
height: self.minimum_height
cols: 2
rows: 4
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'
MyLabel:
text: 'Filler'

Button:
text: 'Home'
size_hint: 1, .1
on_press: root.manager.current = 'home'
Button:
text: 'Settings'
size_hint: 1, .1
on_press: root.manager.current = 'settings'

关于python - 如何使 Kivy 屏幕的一部分可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39170283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com