Python | Widget de carrusel en Kivy – Part 1

Kivy es una herramienta GUI independiente de la plataforma en Python. Como se puede ejecutar en Android, IOS, Linux y Windows, etc. B谩sicamente se usa para desarrollar la aplicaci贸n de Android, pero eso no significa que no se pueda usar en aplicaciones de escritorio.

馃憠馃徑 Tutorial de Kivy: aprenda Kivy con ejemplos .

Widget de carrusel:

El widget de carrusel proporciona la cl谩sica vista de carrusel compatible con dispositivos m贸viles en la que puede pasar de una diapositiva a otra. Puede agregar cualquier contenido al carrusel y hacer que se mueva horizontal o verticalmente. El carrusel puede mostrar p谩ginas en secuencia o en bucle.

Algunos puntos importantes a tener en cuenta:

1) Proporciona facilidad para atravesar un conjunto de diapositivas.
2) Puede contener im谩genes, videos o cualquier otro contenido
3) El movimiento puede ser vertical u horizontal
4) Kivy proporciona varias personalizaciones para un carrusel que incluyen:

  • Efecto de animaci贸n mientras se realiza una transici贸n de una diapositiva a otra, duraci贸n del per铆odo de transici贸n
  • Especificaci贸n de la direcci贸n del deslizamiento
  • Deshabilitar deslizamientos verticales
  • Si el carrusel debe repetirse infinitamente o no
  • Especificaci贸n de la distancia m铆nima a considerar al aceptar un deslizamiento
  • Especificaci贸n de la duraci贸n m铆nima a considerar al aceptar un deslizamiento
  • Especificaci贸n de las diapositivas actual, anterior y siguiente

Para trabajar con este widget debes tener que importar:

from kivy.uix.carousel import Carousel
Basic Approach:
1) import kivy
2) import kivy App
3) import Gridlayout
4) import widget
5) set minimum version(optional)
6) Create as much as widget class as needed
7) create the App class
8) return the widget/layout etc class
9) Run an instance of the class

Implementaci贸n del Enfoque:

# Program to explain how to add carousel in kivy聽
聽聽聽聽
# import kivy module聽聽聽聽
import kivy聽聽
聽聽聽聽聽聽
# base Class of your App inherits from the App class.聽聽聽聽
# app:always refers to the instance of your application聽聽聽
from kivy.app import App聽
聽聽聽聽
# this restrict the kivy version i.e聽聽
# below this kivy version you cannot聽聽
# use the app or software聽聽
kivy.require('1.9.0')聽
聽聽聽聽
# The Image widget is used to display an image聽
# this module contain all features of images聽
from kivy.uix.image import AsyncImage
聽聽
# The Carousel widget provides the
# classic mobile-friendly carousel
# view where you can swipe between slides
from kivy.uix.carousel import Carousel
聽聽
聽聽
聽聽
# Create the App class
class CarouselApp(App):
聽聽聽聽def build(self):
聽聽
聽聽聽聽聽聽聽聽# Add carousel
聽聽聽聽聽聽聽聽# And add the direction of swipe
聽聽聽聽聽聽聽聽carousel = Carousel(direction ='right')
聽聽
聽聽聽聽聽聽聽聽# Adding 10 slides
聽聽聽聽聽聽聽聽for i in range(10):
聽聽聽聽聽聽聽聽聽聽聽聽src = "http://placehold.it / 480x270.png&text = slide-%d&.png" %i
聽聽聽聽聽聽聽聽聽聽聽聽# using Asynchronous image聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽image = AsyncImage(source = src, allow_stretch = True)
聽聽聽聽聽聽聽聽聽聽聽聽carousel.add_widget(image)
聽聽聽聽聽聽聽聽return carousel
聽聽
# Run the App
CarouselApp().run()

Producci贸n:

Publicaci贸n traducida autom谩ticamente

Art铆culo escrito por YashKhandelwal8 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu direcci贸n de correo electr贸nico no ser谩 publicada. Los campos obligatorios est谩n marcados con *