• # A working example OO ;-)

    Posté par (site web personnel) . En réponse au journal htag : realiser des UI en python3 sur web, mobile et desktop.. Évalué à 2.

    Le site officiel : https://github.com/manatlan/htag

    Juste un exemple qui fonctionnera OOTB sur votre poste, après un pip install htag !

    Créer le fichier suivant, et lancer le :

     from htag import Tag
     class Stars(Tag.div):
     def init(self,nb):
     self["style"] = "background: #"+hex(nb*666)[2:]
     self <= "⭐" * nb
     class MyApp(Tag.body):
     def init(self):
     self.main = Tag.div()
     # create the layout
     self <= Tag.button("3",nb=3,_onclick=self.click )
     self <= Tag.button("4",nb=4,_onclick=self.click )
     self <= Tag.button("5",nb=5,_onclick=self.click )
     self <= Tag.button("clear",_onclick=lambda o: self.main.clear() )
     self <= self.main
     def click(self, o):
     self.main <= Stars(o.nb)
     #======================================
     from htag.runners import BrowserHTTP as Runner # need htag only !
     #~ from htag.runners import DevApp as Runner # need htag+uvicorn+starlette !
     app=Runner( MyApp )
     if __name__=="__main__":
     app.run()