Kivy - My ScrollView doesn#39;t scroll(Kivy - 我的 ScrollView 不滚动)
问题描述
我在使用 Kivy 库的 Python 应用程序中遇到问题.特别是我试图在 TabbedPanelItem 中创建一个可滚动的元素列表,但我不知道为什么我的列表不滚动.
I'm having problems in my Python application with Kivy library. In particular I'm trying to create a scrollable list of elements in a TabbedPanelItem, but I don't know why my list doesn't scroll.
这是我的 kv 文件:
Here is my kv file:
#:import sm kivy.uix.screenmanager
ScreenManagement:
transition: sm.FadeTransition()
SecondScreen:
<SecondScreen>:
tabba: tabba
name: 'second'
FloatLayout:
background_color: (255, 255, 255, 1.0)
BoxLayout:
orientation: 'vertical'
size_hint: 1, 0.10
pos_hint: {'top': 1.0}
canvas:
Color:
rgba: (0.98, 0.4, 0, 1.0)
Rectangle:
pos: self.pos
size: self.size
Label:
text: 'MyApp'
font_size: 30
size: self.texture_size
BoxLayout:
orientation: 'vertical'
size_hint: 1, 0.90
Tabba:
id: tabba
BoxLayout:
orientation: 'vertical'
size_hint: 1, 0.10
pos_hint: {'bottom': 1.0}
Button:
background_color: (80, 1, 0, 1.0)
text: 'Do nop'
font_size: 25
<Tabba>:
do_default_tab: False
background_color: (255, 255, 255, 1.0)
TabbedPanelItem:
text: 'First_Tab'
Tabs:
TabbedPanelItem:
text: 'Second_Tab'
Tabs:
TabbedPanelItem:
text: 'Third_Tab'
Tabs:
<Tabs>:
grid: grid
ScrollView:
scroll_timeout: 250
scroll_distance: 20
do_scroll_y: True
do_scroll_x: False
GridLayout:
id: grid
cols: 1
spacing: 10
padding: 10
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
Label:
text:'scroll'
color: (0, 0, 0, 1.0)
这里是我的 .py 代码:
And here my .py code:
__author__ = 'drakenden'
__version__ = '0.1'
import kivy
kivy.require('1.9.0') # replace with your current kivy version !
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.properties import StringProperty, ObjectProperty,NumericProperty
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.utils import platform
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
class Tabs(ScrollView):
def __init__(self, **kwargs):
super(Tabs, self).__init__(**kwargs)
class Tabba(TabbedPanel):
pass
class SecondScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("layout2.kv")
class MyApp(App):
def build(self):
return presentation
MyApp().run()
我在哪里/我做错了什么?
Where/What am I doing wrong?
(也接受对 UI 改进的评论和建议)
(Comments and suggests for UI improvements are also accepted)
推荐答案
我自己也有一段时间没用过kivy了,如果我记得很清楚的话:因为 ScrollView 中的布局应该比滚动视图大例如 ScrollView 宽度:1000 像素,GridView 1100 像素.所以可以滚动100px
I Myself haven't used kivy for a while but if I remember exacly: Because layout within ScrollView should be BIGGER than scroll view ex ScrollView width: 1000px, GridView 1100px. So it will be possible to scroll it by 100px
这篇关于Kivy - 我的 ScrollView 不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Kivy - 我的 ScrollView 不滚动
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01