issue181:python
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 | ||
issue181:python [2022/05/28 08:15] – d52fr | issue181:python [2022/06/02 19:20] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 6: | Ligne 6: | ||
Part of the confusion for many programmers is what exactly are Themes and what are Styles.** | Part of the confusion for many programmers is what exactly are Themes and what are Styles.** | ||
+ | |||
+ | Pendant la création de PAGE 7.4, j' | ||
+ | |||
+ | Pendant la création de la démo, je me suis rendu compte que je ne maîtrisais pas vraiment les styles et les thèmes. Le sujet est peu documenté, même dans le monde Tcl/Tk, et lorsqu' | ||
+ | |||
+ | De nombreux programmeurs qui utilisent Tkinter aiment ou détestent les widgets, styles et thèmes de ttk. Beaucoup, comme moi, évitent les widgets ttk à moins que ce ne soit une nécessité absolue. La plupart du temps, lorsque je conçois une interface graphique, j' | ||
+ | |||
+ | Pour de nombreux programmeurs, | ||
+ | |||
**Styles concern the look and feel of a single widget. A Theme is a collection of Styles that share attributes like background colors and foreground colors, across many ttk widgets. | **Styles concern the look and feel of a single widget. A Theme is a collection of Styles that share attributes like background colors and foreground colors, across many ttk widgets. | ||
Ligne 12: | Ligne 21: | ||
One of the most frustrating parts of creating the widget demo was fighting the TNotebook colors for the tabs. Take a look at this image:** | One of the most frustrating parts of creating the widget demo was fighting the TNotebook colors for the tabs. Take a look at this image:** | ||
+ | |||
+ | Les Styles concernent l' | ||
+ | |||
+ | Bien que cela soit assez facile à comprendre, pour Linux, il n'y a que quatre Thèmes prédéfinis pour les widgets ttk. Ce sont Alt, Clam, Classic et Default. Ceux qui utilisent Windows ont quelques thèmes supplémentaires, | ||
+ | |||
+ | L'une des parties les plus frustrantes de la création de la démo des widgets a été la lutte contre les couleurs pour les onglets de TNotebook. Jetez un coup d'œil à cette image : | ||
**You can see that Tab 2 is the current or selected tab, Tab 3 is sort of highlighted when the mouse is over the tab, and the other two are somewhat obvious that you aren’t dealing with them at the moment. But if you are color challenged, like me, it’s not always obvious. Wouldn’t it be better to be able to present your user with something like this: | **You can see that Tab 2 is the current or selected tab, Tab 3 is sort of highlighted when the mouse is over the tab, and the other two are somewhat obvious that you aren’t dealing with them at the moment. But if you are color challenged, like me, it’s not always obvious. Wouldn’t it be better to be able to present your user with something like this: | ||
Ligne 20: | Ligne 35: | ||
The style.configure method allows you to set the basic background and foreground colors, but what does the style.map method do and why would I do it?** | The style.configure method allows you to set the basic background and foreground colors, but what does the style.map method do and why would I do it?** | ||
+ | |||
+ | Vous pouvez voir que l' | ||
+ | |||
+ | Il est immédiatement évident que l' | ||
+ | |||
+ | En fouillant dans le fichier GUI.py créé par PAGE, j'ai trouvé le premier indice (voir le code, page suivante, en bas à droite). | ||
+ | |||
+ | La méthode style.configure permet de définir les couleurs de base de l' | ||
+ | |||
**Well, with a bunch more digging around in various documentation and websites, I found out that the .map method allows you to set different colors to different states for the widget. So in the above code, the “selected” state is when the tab is actually selected and the “active” state is when the mouse is hovering over the tab. Notice that for the moment, we are only talking about the TNotebook tabs. But what about the other tabs that are “just hanging out”. That took some more digging to answer. It turns out that there is another state called “!active” that covers those tabs. Once I figured the hex codes for the colors I wanted I was ready. | **Well, with a bunch more digging around in various documentation and websites, I found out that the .map method allows you to set different colors to different states for the widget. So in the above code, the “selected” state is when the tab is actually selected and the “active” state is when the mouse is hovering over the tab. Notice that for the moment, we are only talking about the TNotebook tabs. But what about the other tabs that are “just hanging out”. That took some more digging to answer. It turns out that there is another state called “!active” that covers those tabs. Once I figured the hex codes for the colors I wanted I was ready. | ||
Ligne 30: | Ligne 54: | ||
When I ran it this time, low and behold, it worked!** | When I ran it this time, low and behold, it worked!** | ||
+ | |||
+ | Eh bien, en creusant un peu plus dans diverses documentations et sites Web, j'ai découvert que la méthode .map vous permet de définir différentes couleurs pour différents états du widget. Ainsi, dans le code ci-dessus, l' | ||
+ | |||
+ | Lorsque j'ai commencé à coder (en haut à droite), étant donné le programmeur paresseux que je suis, j'ai créé un programme de test rapide en PAGE avec juste un TNotebook dessus, puis j'ai créé une fonction de démarrage pour définir les couleurs et les affecter au widget. | ||
+ | |||
+ | Lorsque j'ai exécuté le programme, j'ai été déçu. | ||
+ | |||
+ | Je suis rapidement retourné dans la documentation et sur divers sites Web pour essayer de comprendre ce qui me manquait. Il s'est avéré que le simple fait de définir map de TNotebook ne s' | ||
+ | |||
+ | Lorsque je l'ai exécuté cette fois-ci, cela a fonctionné ! | ||
+ | |||
**Then I tried to apply my new trick to other ttk widgets. Unfortunately, | **Then I tried to apply my new trick to other ttk widgets. Unfortunately, | ||
Ligne 38: | Ligne 73: | ||
_w1.TButton1.configure(background=bg1, | _w1.TButton1.configure(background=bg1, | ||
+ | |||
+ | J'ai ensuite essayé d' | ||
+ | |||
+ | Le code Tcl montre que TButton possède une méthode map, mais les différents états sont très différents de ceux des onglets TNotebook. Il existe un état actif, un état désactivé et un état en lecture seule. (Pourquoi un TButton aurait-il besoin d'un état en lecture seule ? Je ne sais pas, mais apparemment c'est le cas). J'ai donc retravaillé un peu le code pour TButton et j'ai obtenu ceci (en bas à droite). | ||
+ | |||
+ | Lorsque j'ai exécuté mon programme, j'ai été de nouveau déçu. L' | ||
+ | |||
+ | _w1.TButton1.configure(background=bg1, | ||
+ | |||
**That, however, didn’t do it either. Then I remembered that I have to override the style defaults (dull gray background and black foreground). This is “explained” (somewhat) in the New Mexico Tech Tkinter documentation. It turns out that I can create a special style and apply that to my button by using the style attribute (shown bottom left). | **That, however, didn’t do it either. Then I remembered that I have to override the style defaults (dull gray background and black foreground). This is “explained” (somewhat) in the New Mexico Tech Tkinter documentation. It turns out that I can create a special style and apply that to my button by using the style attribute (shown bottom left). | ||
Ligne 46: | Ligne 90: | ||
Until next time, as always; stay safe, healthy, positive and creative!** | Until next time, as always; stay safe, healthy, positive and creative!** | ||
+ | |||
+ | Mais cela n'a pas fonctionné non plus. Je me suis alors souvenu que je devais remplacer les valeurs par défaut du style (arrière-plan gris terne et premier plan noir). Cela est « expliqué » (en quelque sorte) dans la documentation Tkinter de New Mexico Tech. Il s' | ||
+ | |||
+ | Cela a fonctionné ! | ||
+ | |||
+ | Pour en savoir plus sur les tâtonnements dans mon long et ardu voyage pour apprendre à maîtriser les Styles et les Thèmes avec les widgets ttk dans Tkinter, veuillez consulter l' | ||
+ | |||
+ | Jusqu' | ||
+ |
issue181/python.1653718552.txt.gz · Dernière modification : 2022/05/28 08:15 de d52fr