atelier20230316-python-gui
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| atelier20230316-python-gui [2023/03/16 19:52] – tbruyere | atelier20230316-python-gui [2023/03/17 19:42] (Version actuelle) – tbruyere | ||
|---|---|---|---|
| Ligne 45: | Ligne 45: | ||
| * QT | * QT | ||
| * Kivy | * Kivy | ||
| + | * Fet + Flutter(google) | ||
| * PySimpleGUI | * PySimpleGUI | ||
| Ligne 63: | Ligne 64: | ||
| '' | '' | ||
| + | |||
| + | <note tip>La licence est semi libre</ | ||
| ===== Kivy ===== | ===== Kivy ===== | ||
| '' | '' | ||
| + | |||
| + | ===== Flet ===== | ||
| + | |||
| + | Flet est un framework qui permet de créer des applications Web, de bureau et mobiles multi-utilisateurs interactives dans votre langue préférée sans expérience préalable en développement frontend. | ||
| + | |||
| + | Vous créez une interface utilisateur pour votre programme avec des contrôles Flet basés sur Flutter de Google. | ||
| ===== Cas particulier de PySimpleGUI ===== | ===== Cas particulier de PySimpleGUI ===== | ||
| Ligne 134: | Ligne 143: | ||
| et si on demandait à chatgpt : créée moi un hello world en python avec interface graphique wxpython | et si on demandait à chatgpt : créée moi un hello world en python avec interface graphique wxpython | ||
| - | ----> | + | ==== Résultat ==== |
| <code python> | <code python> | ||
| Ligne 175: | Ligne 184: | ||
| </ | </ | ||
| - | ==== et on continue avec QT ==== | + | ==== exemple en QT ==== |
| <code python> | <code python> | ||
| Ligne 195: | Ligne 204: | ||
| sys.exit(app.exec_()) | sys.exit(app.exec_()) | ||
| </ | </ | ||
| + | |||
| + | ==== exemple en Kivy ==== | ||
| + | |||
| + | <code python> | ||
| + | import kivy | ||
| + | kivy.require(' | ||
| + | from kivy.app import App | ||
| + | from kivy.uix.label import Label | ||
| + | |||
| + | class HelloWorldApp(App): | ||
| + | def build(self): | ||
| + | return Label(text=' | ||
| + | |||
| + | if __name__ == ' | ||
| + | HelloWorldApp().run() | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===== La gestion de la grille (grid) ===== | ||
| + | |||
| + | Cette stratégie permet de positionner chacun de vos widgets dans une ou plusieurs cellules d'une grille. La grille est organisée en lignes et en colonnes : vous pouvez, bien entendu, contrôler le nombre de lignes et de colonnes. Il est aussi à noter qu'il est possible qu'un widget occupe plusieurs cellules de la grille. Voici une capture d' | ||
| + | |||
| + | ===== GTK et les conteneurs ===== | ||
| + | |||
| + | GTK+ organise les widgets de manière hiérarchique, | ||
| + | |||
| + | https:// | ||
| + | |||
| + | ==== Exemple GTK ==== | ||
| + | |||
| + | <code python> | ||
| + | import gi | ||
| + | |||
| + | gi.require_version(" | ||
| + | from gi.repository import Gtk | ||
| + | |||
| + | |||
| + | class MyWindow(Gtk.Window): | ||
| + | def __init__(self): | ||
| + | super().__init__(title=" | ||
| + | |||
| + | self.box = Gtk.Box(spacing=6) | ||
| + | self.add(self.box) | ||
| + | |||
| + | self.button1 = Gtk.Button(label=" | ||
| + | self.button1.connect(" | ||
| + | self.box.pack_start(self.button1, | ||
| + | |||
| + | self.button2 = Gtk.Button(label=" | ||
| + | self.button2.connect(" | ||
| + | self.box.pack_start(self.button2, | ||
| + | |||
| + | def on_button1_clicked(self, | ||
| + | print(" | ||
| + | |||
| + | def on_button2_clicked(self, | ||
| + | print(" | ||
| + | |||
| + | |||
| + | win = MyWindow() | ||
| + | win.connect(" | ||
| + | win.show_all() | ||
| + | Gtk.main() | ||
| + | </ | ||
| + | |||
| + | ===== GTK Glade ===== | ||
| + | |||
| + | Glade est un outil interactif de conception d' | ||
| + | |||
| + | ==== Exemple Glade ==== | ||
| + | |||
| + | <code python> | ||
| + | # | ||
| + | # coding: utf-8 | ||
| + | |||
| + | from gi.repository import Gtk | ||
| + | |||
| + | def when_button_is_clicked(label): | ||
| + | ''' | ||
| + | Quand le bouton est cliqué | ||
| + | ''' | ||
| + | label.set_text(' | ||
| + | |||
| + | |||
| + | builder = Gtk.Builder() | ||
| + | builder.add_from_file(' | ||
| + | |||
| + | window = builder.get_object(' | ||
| + | # Peut se faire dans Glade mais je préfère le faire ici, à vous de voir | ||
| + | window.connect(' | ||
| + | |||
| + | # Le handler | ||
| + | handler = {' | ||
| + | builder.connect_signals(handler) | ||
| + | |||
| + | window.show_all() | ||
| + | Gtk.main() | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Lien ===== | ||
| + | |||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | * https:// | ||
| + | | ||
atelier20230316-python-gui.1678996365.txt.gz · Dernière modification : 2023/03/16 19:52 de tbruyere