kivy Scrollview无法滚动

时间:2017-03-30 07:58:25

标签: python uiscrollview kivy

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

这是我的python代码:

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照片。

1 个答案:

答案 0 :(得分:0)

TASKKILL /f /pid 1234 kv代码而不是:

GridLayout

做的:

minimum_height: self.minimum_height

然后它应该工作得很好。 :)

此外,在将来尝试 NOT 以包含您制作的自定义模块(height: self.minimum_height ),因为它会使代码难以重现,除非其他人知道什么寻找......