Creacion de aplicaciones android con python kivymd

Iniciado por $francisco, Noviembre 14, 2019, 09:54:31 PM

Tema anterior - Siguiente tema

0 Miembros y 3 Visitantes están viendo este tema.

Noviembre 14, 2019, 09:54:31 PM Ultima modificación: Noviembre 15, 2019, 11:50:24 AM por $francisco
Muy buenas compañeros, quiero compartir algo a lo que le estoy dedicando un poquito de tiempo y que a los pythoneros seguro les va a gustar.

Vamos a usar kivy, en mas concreto kivymd que es una extensión o librería de kivy, decir que kivy esta creado con sdl2, sdl2 es un conjunto de bibliotecas creadas en C por un desarrollador de videojuegos y que proporciona funciones básicas para crear operaciones de dibujo en 2d.

Ahora con kivymd (kivy material desing) proporciona un estilo que sigue el estándar de diseño que se puso en el sdk 21 o api 5 de esta manera parece que es una aplicacion android real, no solo eso, también tenemos pyjnius que nos proporciona acceder a java desde python y de esta manera podemos acceder al sdk nativo usando pyjnius, también tenemos buildozer que es una herramienta que nos ayuda a compilar a apk o a ios.

Creamos nuestro archivo No tienes permitido ver los links. Registrarse o Entrar a mi cuenta que sera el punto de entrada de nuestra aplicación.

Código: python
from kivy.app import App
from kivymd.theming import ThemeManager


class Main(App):
    theme_cls = ThemeManager()

    def open_menu(self, widget):
        self.root.toggle_nav_drawer()

    def imprimir(self, texto):
        print(texto)

Main().run()


Este es el punto de entrada y theme_cls es lo que va a buscar cuando se genera la instancia, es lo que proporciona kivymd y es donde se comienza a crear la magia.

Ahora vamos a crear el main.kv

Código: text
NavigationLayout:
    MDNavigationDrawer:
        drawer_logo: "menu.png"
        NavigationDrawerIconButton:
            icon: "home"
            text: "Inicio"
            on_release: screen_manager.current = "screen1"

        NavigationDrawerIconButton:
            icon: "lock"
            text: "Pagina 2"
            on_release: screen_manager.current = "screen2"

    BoxLayout:
        orientation: "vertical"
        MDToolbar:
            title: "App"
            md_bg_color: app.theme_cls.primary_color
            left_action_items: [["menu", app.open_menu]]
        ScreenManager:
            id: screen_manager
            Screen:
                name: "screen1"
                FloatLayout:
                    MDLabel:
                        text: "Screen 1"
                        size_hint: (0.5, 0.1)
                        pos_hint: {"center_x": 0.5, "center_y": 0.9}
                        halign: "center"

                    MDRoundFlatButton:
                        text: "Imprimir"
                        pos_hint: {"center_x": 0.5, "center_y": 0.8}
                        on_release: app.imprimir("Screen 1")

            Screen:
                name: "screen2"
                FloatLayout:
                    MDLabel:
                        text: "Screen 2"
                        size_hint: (0.5, 0.1)
                        pos_hint: {"center_x": 0.5, "center_y": 0.9}
                        halign: "center"

                    MDRoundFlatButton:
                        text: "Imprimir"
                        pos_hint: {"center_x": 0.5, "center_y": 0.8}
                        on_release: app.imprimir("Screen 2")


El archivo main.kv es el archivo que carga por defecto al crear la instancia de nuestra aplicación, si ejecutamos esto veremos nuestra aplicación funcionando.

No tienes permitido ver los links. Registrarse o Entrar a mi cuenta







Gracias amigo te agrazco por ese aporte....

serias tan amable de recomentarme contenido en donde puedo aprehender sobre la libreria de FrameWork de Kivy, en españos 

El Framework kivy en mi parecer la dio mas fuerza a python, lo malo de kivy que no mucha documentación de este framework

Udenmy ofrece ub curso para la creacion de aplicaicon de androi y para ios lo unico que no es gratis

Hola, ¿podrías ayudarme? soy novato utilizando python y encontré ese mismo vídeo pero cuando lo corro me parece lo siguiente en mi terminal :

[INFO   ] [Logger      ] Record log in C:\Users\joaquis\.kivy\logs\kivy_20-05-01_33.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.2.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.1.10
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.2.0
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.2.0
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\pythonw.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [KivyMD      ] v0.104.1
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.1.11161 Compatibility Profile Context'>
[INFO   ] [GL          ] OpenGL vendor <b'ATI Technologies Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'AMD Radeon(TM) HD 6480G     '>
[INFO   ] [GL          ] OpenGL parsed version: 4, 1
[INFO   ] [GL          ] Shading version <b'4.10'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [GL          ] NPOT texture support is available
Traceback (most recent call last):
   File "C:/Users/joaquis/PycharmProjects/IDKPROYECTO/main.py", line 15, in <module>
     Main().run()
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line 828, in run
     self.load_kv(filename=self.kv_file)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line 599, in load_kv
     root = Builder.load_file(rfilename)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
     return self.load_string(data, **kwargs)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 405, in load_string
     rule_children=rule_children)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\lang\builder.py", line 654, in _apply_rule
     child = cls(__no_builder=True)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivymd\uix\navigationdrawer.py", line 516, in __init__
     super().__init__(**kwargs)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivymd\uix\card.py", line 664, in __init__
     super().__init__(**kwargs)
   File "C:\Users\joaquis\AppData\Local\Programs\Python\Python37\lib\site-packages\kivymd\theming.py", line 896, in __init__
     "KivyMD: App object must be inherited from "
ValueError: KivyMD: App object must be inherited from `kivymd.app.MDApp`. See No tienes permitido ver los links. Registrarse o Entrar a mi cuenta

Process finished with exit code 1

Mayo 13, 2022, 02:39:24 PM #5 Ultima modificación: Mayo 16, 2022, 03:01:52 PM por Posterejul
Estaré subiendo ejemplos de aplicaciones en kivymd en mi blog No tienes permitido ver los links. Registrarse o Entrar a mi cuenta por si a alguien le interesa

No tienes permitido ver los links. Registrarse o Entrar a mi cuentaUdenmy ofrece ub curso para la creacion de aplicaicon de androi y para ios lo unico que no es gratis

Aún están disponibles los cursos ?