2017-10-06 9 views
0

pythonで動作し、kivyで実行される画像スライドショーの作成に問題があります。KivyとPythonクリックしたときに移動するスライドショーを作成する

私は非同期を使用していますが、スライドショーを作成して写真を開き、次に右にクリックすると前方に進みますが、マウスが左にクリックされると前のページに移動しますページ(画像)。

ありがとうございました。

答えて

0

ボタンからコメント#を削除し、必要に応じて左右の方法を移動できますが、カルーセル方向の機能がその問題を解決すると思います。心配しています。私は初心者ですので、これは私の手伝いです。私はここで多くの助けを得て以来、私は他の人を助けるだろうと思った。このおかげで

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() 

希望は、あなたが

を必要とするものです
関連する問題