3 usuarios conectados

Desarrollo de interfaces gráficas de usuarios (GUIS). Librerías. wxPython

Comparte esto

Desarrollo de interfaces gráficas de usuarios (GUIS). Librerías. wxPython

Compra libros de Python en Amazon al mejor precio

Kivy es un framework de Python muy interesante para el desarrollo de aplicaciones con interfaces de usuario innovadoras y con soporte multitáctil, que además son multiplataforma.

Si vas a incluir una sección sobre Kivy en tu página web de programación en Python, aquí tienes algunas ideas de temas y código de ejemplo que podrías cubrir:

Temas para la Sección de Kivy:

Ejemplo de Código en Python y Kv (Calculadora Simple):

calculadora.py (Python):

Python
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label

class Calculadora(App):
    def build(self):
        return InterfazCalculadora()

class InterfazCalculadora(BoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.orientation = 'vertical'
        self.display = Label(text='0', font_size=40, halign='right', valign='middle', size_hint=(1, 0.3))
        self.add_widget(self.display)
        self.buttons = [
            '7', '8', '9', '/',
            '4', '5', '6', '*',
            '1', '2', '3', '-',
            '.', '0', '=', '+'
        ]
        grid = BoxLayout(orientation='horizontal', size_hint=(1, 0.7), row_force_default=True, row_default_height=40)
        for button_text in self.buttons:
            btn = Button(text=button_text, font_size=30)
            btn.bind(on_press=self.on_button_click)
            grid.add_widget(btn)
        self.add_widget(grid)
        self.current_operation = ''

    def on_button_click(self, instance):
        text = instance.text
        if text == '=':
            try:
                self.display.text = str(eval(self.current_operation))
                self.current_operation = ''
            except Exception:
                self.display.text = 'Error'
                self.current_operation = ''
        elif text == 'C':
            self.display.text = '0'
            self.current_operation = ''
        else:
            self.current_operation += text
            self.display.text = self.current_operation

if __name__ == '__main__':
    Calculadora().run()

calculadora.kv (Kv - opcional, pero recomendable):

Fragmento de código
 
<InterfazCalculadora>:
    orientation: 'vertical'
    Label:
        id: display
        text: '0'
        font_size: 40
        halign: 'right'
        valign: 'middle'
        size_hint: (1, 0.3)
    GridLayout:
        cols: 4
        size_hint: (1, 0.7)
        Button:
            text: '7'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '8'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '9'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '/'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '4'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '5'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '6'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '*'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '1'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '2'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '3'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '-'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '.'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '0'
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '='
            font_size: 30
            on_press: root.on_button_click(self)
        Button:
            text: '+'
            font_size: 30
            on_press: root.on_button_click(self)

Este ejemplo muestra una calculadora simple creada con Kivy, separando la interfaz en el archivo .kv y la lógica en el archivo .py. Puedes usarlo como punto de partida para explicar los conceptos básicos de Kivy en tu sitio web.