简体   繁体   English

kivy Scrollview无法滚动

[英]kivy Scrollview can't Scroll

FileView extends the kivy ScrollView. FileView扩展了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. 但是,我无法滚动。

This is my python code: 这是我的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()

This is my kv file: 这是我的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'

The method show_Photos_in_folder() of my PhotoRoot is called to display the supposedly scrollable GridLayout of photos. 调用我的PhotoRoot的show_Photos_in_folder()方法以显示照片的所谓可滚动GridLayout。

In GridLayout kv code instead of: GridLayout kv代码中,而不是:

minimum_height: self.minimum_height

do: 做:

height: self.minimum_height

Then it should work just fine. 然后它应该工作正常。 :) :)

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... 另外,将来不要尝试包含您制作的自定义模块( import unknown_module... ),因为除非他人知道要查找的内容,否则它将导致代码难以复制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM