kivy Scrollview无法滚动 [英] kivy Scrollview can't Scroll

查看:263
本文介绍了kivy Scrollview无法滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileView扩展了kivy ScrollView.在应用程序中,我可以看到四个图像中的三个,但是我无法滚动到第四个图像.因此,该小部件比我的应用程序窗口大,我认为我应该能够滚动.但是,我无法滚动.

FileView extends the kivy ScrollView. In the app I can see three out of the four image, but I am not able to scroll to the fourth image. Therefore the widget is larger than my app window and I thought that I should be able to scroll. But, I cannot scroll.

这是我的python代码:

This is my python code:

import os
import sys

#self-programmed modules
import modules.pmail as pmail
import modules.log as log

#kivy modules
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.scrollview import ScrollView
from kivy.core.window import Window
from kivy.properties import StringProperty

logging = True
log.start(logging)

class FileViewPhoto(Button):
    source = StringProperty()

class FileView(ScrollView):
    pass

class Photo(BoxLayout):
    pass


class PhotoCamera(BoxLayout):
    '''
    Start screen, from here a photo or gif can be taken or previously taken images be viewed
    '''
    def take_pic(self):
        log.printlog('take_pic', logging)
        App.get_running_app().root.show_Photo()

    def take_gif(self):
        log.printlog('take_gif', logging)
        App.get_running_app().root.show_Photo()



class PhotoRoot(BoxLayout):
    '''
    Root widget
    -all methods which change the content of the screen are called from here.
    '''
    def show_Photo(self):
        self.clear_widgets()
        self.add_widget(Photo())

    def show_Photos_in_folder(self):
        self.clear_widgets()
        self.add_widget(FileView())

class PhotoboothApp(App):

    def build(self):
        self.icon = 'Icons/photo.png'


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

这是我的kv文件:

PhotoRoot:
    PhotoCamera:

<PhotoCamera>:
    Button:
        text: 'Camera-Gif'
        on_press: root.take_gif()
        BoxLayout:
            orientation:'vertical'
            pos: self.parent.pos
            size: self.parent.size
            Image:
                source: 'Icons/photo.png'
            Image:
                source: 'Icons/photo.png'
            Image:
                source: 'Icons/photo.png'
    Button:
        on_press: root.take_pic()
        Image:
            width: self.parent.width
            source: 'Icons/photo.png'
            center: self.parent.center

    Button:
        text: 'Photos'
        on_press: app.root.show_Photos_in_folder()

<Photo>:
    Label:
        text: 'Photo'
    Image:
        source: 'Images/Astronaut1.jpg'

<FileViewPhoto>:
    source: ''
    size_hint_y: None
    height: '300sp'
    Image:
        source: root.source
        center: root.center
        size: root.size

<FileView>:

    GridLayout:
        cols: 1
        size_hint_y: None
        row_default_height: '200dp'
        row_force_default: True
        minimum_height: self.minimum_height

        FileViewPhoto:
            source: 'Images/Astronaut1.jpg'

        FileViewPhoto
            source: 'Images/Astronaut1.jpg'

        FileViewPhoto
            source: 'Images/Astronaut1.jpg'

        FileViewPhoto:
            source: 'Images/Astronaut1.jpg'

调用我的PhotoRoot的show_Photos_in_folder()方法以显示照片的可滚动GridLayout.

The method show_Photos_in_folder() of my PhotoRoot is called to display the supposedly scrollable GridLayout of photos.

推荐答案

GridLayout kv代码中,而不是:

In GridLayout kv code instead of:

minimum_height: self.minimum_height

这样做:

height: self.minimum_height

然后它应该可以正常工作. :)

Then it should work just fine. :)

此外,将来尝试 不要 包含您制作的自定义模块(import unknown_module...),因为除非其他人知道外观,否则这会使代码难以复制为...

Also, in future try NOT to include custom modules you made (import unknown_module...) as it makes the code hard to reproduce unless the other person knows what to look for...

这篇关于kivy Scrollview无法滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆