Kivy和Python创建一个幻灯片,当点击时移动

问题描述:

我在制作一个图片幻灯片,与python一起运行并用kivy执行时遇到问题。Kivy和Python创建一个幻灯片,当点击时移动

我使用异步,但我想要使幻灯片显示,以便我打开照片,然后当我点击右边前进,但如果鼠标点击左侧,然后它去往前页面(图片)。

感谢您的帮助。

如果需要,您可以从按钮中移除注释#并移动左/右方法,但我认为旋转木马方向功能可以解决该问题。请注意,我是一名新手,所以这只是我帮助的方式。我想我会帮助其他人,因为我在这里得到了很多帮助。由于

from kivy.app import App 
from kivy.loader import Loader 
from kivy.lang import Builder 
from kivy.base import runTouchApp 
from kivy.clock import Clock 
from kivy.properties import * 
from kivy.uix.image import AsyncImage 
from kivy.uix.gridlayout import GridLayout 
from kivy.uix.carousel import Carousel 
from kivy.uix.button import Button 

Builder.load_string(''' 
<MyWidget>: 
    carousel: carousel 
    cols: 1 
    Button: 
     pos_hint: {"center_x":0.5, "center_y":0.1} 
     size_hint: .3,.1 
     font_size: 35 
     text: str(root.on_off) 
     on_release: root.start_slide() 
    Carousel: 
     pos_hint: {"center_x":0.5, "center_y":0.9} 
     id: carousel 
     direction: 'right' 
     loop: True 
     index: 0 
''') 

class MyWidget(GridLayout): 
    on_off = StringProperty('Start') 
    slide_count = NumericProperty(11) 
    def __init__(self, **kwargs): 
     super(MyWidget, self).__init__() 
     self.carousel = Carousel(direction='right') 
     self.add_widget(self.carousel) 
     for i in range(self.slide_count): 
      src = "http://placehold.it/480x270.png&text=slide-%d&.png" % i 
      image = AsyncImage(source=src, allow_stretch=True) 
      self.carousel.add_widget(image) 
     #self.start_slide()### Uncomment this to start slideshow when the app starts 

    def start_slide(self, *args): 
     if self.on_off == 'Start': 
      self.on_off = 'Stop' 
      self.clock = Clock.schedule_interval(self.slide_next, 3) ##move right every 3 seconds 
      return 
     if self.on_off == 'Stop': 
      self.on_off = 'Start' 
      Clock.unschedule(self.clock) 
      self.carousel.index = 0 

    def slide_next(self, *args): 
     if self.carousel.index == (self.slide_count - 1): 
      self.carousel.index = 0### This keeps the loops intact 
      #### if you want to end the slideshow at the last image, use 'Clock.unschedule(self.clock)' instead 
      return 
     self.carousel.load_next() 

class SlideShowApp(App): 

    def build(self): 
     mywidget = MyWidget() 
     return mywidget 

if __name__ == '__main__': 

    SlideShowApp().run() 

希望这是你需要什么