簡體   English   中英

kivy Scrollview無法滾動

[英]kivy Scrollview can't Scroll

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。

GridLayout kv代碼中,而不是:

minimum_height: self.minimum_height

做:

height: self.minimum_height

然后它應該工作正常。 :)

另外,將來不要嘗試包含您制作的自定義模塊( import unknown_module... ),因為除非他人知道要查找的內容,否則它將導致代碼難以復制。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM