issue188: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 | ||
issue188:python [2023/01/03 11:46] – d52fr | issue188:python [2023/01/06 14:50] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 12: | Ligne 12: | ||
• A padding element, and | • A padding element, and | ||
• A label element. This element contains the label text, image or both.** | • A label element. This element contains the label text, image or both.** | ||
+ | |||
+ | Dans le numéro 181 du FCM, j'ai parlé des thèmes et des styles et de la façon dont j' | ||
+ | |||
+ | J'en suis arrivé au chapitre de mon livre sur l' | ||
+ | |||
+ | Tout commence par un style. Les styles contrôlent l' | ||
+ | |||
+ | Comme tout commence par un style pour les widgets, nous allons nous pencher sur une seule classe de widgets pour commencer. Nous allons commencer par la classe ttk Button. Le style de cette classe de widget s' | ||
+ | |||
+ | Chaque style de widget est composé d'un ou plusieurs éléments. Un bouton typique comporte quatre éléments : | ||
+ | ••la bordure autour de l' | ||
+ | ••un élément de mise en évidence qui change de couleur lorsque le bouton a le focus d' | ||
+ | ••un élément de remplissage, | ||
+ | ••un élément d' | ||
+ | |||
**Every widget has a style that is controlled by the Theme. Now here is where it gets somewhat frustrating. Each Operating System has its own built-in themes, and some Operating Systems have more built-in themes than others. Since we are a Linux-based magazine, I’ll give them to you now, and then give you the ones for the other Operating Systems. | **Every widget has a style that is controlled by the Theme. Now here is where it gets somewhat frustrating. Each Operating System has its own built-in themes, and some Operating Systems have more built-in themes than others. Since we are a Linux-based magazine, I’ll give them to you now, and then give you the ones for the other Operating Systems. | ||
Ligne 18: | Ligne 33: | ||
When you decide to start working on your own styles, and get ready to wrap them all up in a theme, you should base everything on one theme. For Linux users like us, the simplest theme to start with would be the default theme. Not only does every OS have the default theme built in, but each OS has a different “default” theme that, if you don’t set a specific theme, it will be used by “default”. A logical person would think that that would be default. And you are right, if you are talking about Linux. For Windows, the default theme is winnative, not default and for Mac OS X it is aqua. Talk about confusion!** | When you decide to start working on your own styles, and get ready to wrap them all up in a theme, you should base everything on one theme. For Linux users like us, the simplest theme to start with would be the default theme. Not only does every OS have the default theme built in, but each OS has a different “default” theme that, if you don’t set a specific theme, it will be used by “default”. A logical person would think that that would be default. And you are right, if you are talking about Linux. For Windows, the default theme is winnative, not default and for Mac OS X it is aqua. Talk about confusion!** | ||
+ | |||
+ | Chaque widget a un style qui est contrôlé par le thème. C'est ici que cela devient quelque peu frustrant. Chaque système d' | ||
+ | |||
+ | Il est évident que Linux n'est pas le mieux loti en ce qui concerne le nombre de thèmes fournis avec le système d' | ||
+ | |||
+ | Lorsque vous décidez de commencer à travailler sur vos propres styles et que vous êtes prêt à les intégrer dans un thème, vous devez tout baser sur un seul thème. Pour les utilisateurs de Linux comme nous, le thème le plus simple pour commencer est le thème par défaut. Tous les systèmes d' | ||
+ | |||
**Anyway, we’ll use the ttk Button – to see what our styles can do. Now, remember back a few paragraphs, we touched on the Elements. So for the ttk Button class, the style name is TButton. The elements are assembled into an “empty box”. For a Button under the default theme, they are assembled from the outside in using this order. Border, focus, padding, and, finally, label. Just like the diagram above. | **Anyway, we’ll use the ttk Button – to see what our styles can do. Now, remember back a few paragraphs, we touched on the Elements. So for the ttk Button class, the style name is TButton. The elements are assembled into an “empty box”. For a Button under the default theme, they are assembled from the outside in using this order. Border, focus, padding, and, finally, label. Just like the diagram above. | ||
Ligne 24: | Ligne 46: | ||
Most of the ttk styles have a layout that organizes the different layers that make up the widget style. Some widget classes don’t have a layout. As long as the widget has a layout, you can use the following commands in the Python REPL to get information on the layout. (shown top right).** | Most of the ttk styles have a layout that organizes the different layers that make up the widget style. Some widget classes don’t have a layout. As long as the widget has a layout, you can use the following commands in the Python REPL to get information on the layout. (shown top right).** | ||
+ | |||
+ | Quoi qu'il en soit, nous allons utiliser le bouton ttk, pour voir ce que nos styles peuvent faire. Rappelez-vous, | ||
+ | |||
+ | Chacun de ces éléments possède un attribut « sticky » (collant) qui définit le côté de la « boîte » sur lequel il va se coller. Si, par exemple, un élément a « ew » (est-ouest) pour l' | ||
+ | |||
+ | La plupart des styles ttk ont une disposition qui organise les différentes couches qui composent le style du widget. Certaines classes de widgets n'ont pas de disposition. Tant que le widget a une disposition (layout), vous pouvez utiliser les commandes suivantes dans le REPL Python pour obtenir des informations sur ce layout (en haut à droite). | ||
+ | |||
**Now that is as clear as mud, isn’t it? When a widget class has a layout, it will be returned as a list of tuples which have the element name and a dictionary that describes that element. (I just added a bunch more mud, didn’t I?). | **Now that is as clear as mud, isn’t it? When a widget class has a layout, it will be returned as a list of tuples which have the element name and a dictionary that describes that element. (I just added a bunch more mud, didn’t I?). | ||
Ligne 30: | Ligne 59: | ||
Now, it’s time for me to pull on my “Wellies” (Rubber Boots for those who aren’t Brits, either in family, or location, or heart), and stomp around a little bit more. Each of those elements can (but don’t have to) have options. I’m just going to dump out the options for each of the elements (below).** | Now, it’s time for me to pull on my “Wellies” (Rubber Boots for those who aren’t Brits, either in family, or location, or heart), and stomp around a little bit more. Each of those elements can (but don’t have to) have options. I’m just going to dump out the options for each of the elements (below).** | ||
+ | |||
+ | C'est clair comme de la boue, n' | ||
+ | |||
+ | Pensez-y de cette façon. L' | ||
+ | |||
+ | Maintenant, il est temps pour moi d' | ||
+ | |||
**These are the easiest things that we can change to make our style look the way we want. Notice that I said the easiest things. There can also be images, but that is a discussion for another article. For now, we’ll go back to the element options. | **These are the easiest things that we can change to make our style look the way we want. Notice that I said the easiest things. There can also be images, but that is a discussion for another article. For now, we’ll go back to the element options. | ||
Ligne 39: | Ligne 75: | ||
Nothing fancy. First we set up a custom style for a specific TButton, then set (in this case) the foreground, background and font. Then, when we place the TButton, we can use the standard configure method to set the text, and the style to our Custom.TButton style. | Nothing fancy. First we set up a custom style for a specific TButton, then set (in this case) the foreground, background and font. Then, when we place the TButton, we can use the standard configure method to set the text, and the style to our Custom.TButton style. | ||
Not hard at all. Now let’s customize some TRadiobuttons and TCheckbuttons. Here they are in their “native” state.** | Not hard at all. Now let’s customize some TRadiobuttons and TCheckbuttons. Here they are in their “native” state.** | ||
+ | |||
+ | Ce sont les choses les plus simples que nous pouvons changer pour que notre style soit comme nous le voulons. Remarquez que j'ai dit les choses les plus faciles. Il peut aussi y avoir des images, mais ce sera le sujet d'un autre article. Pour l' | ||
+ | |||
+ | Avant de commencer à modifier les choses, regardons à quoi ressemble TButton lors d'une « journée normale » sous le thème Linux par défaut. | ||
+ | |||
+ | Très fade. Il ressemble à ce que l'on pourrait imaginer pour un bouton. Maintenant, pour définir quoi que ce soit, nous utiliserions le schéma général de stylename.configure(option=value) pour définir les choses à notre manière. Définissons donc les options afin d' | ||
+ | |||
+ | Rien d' | ||
+ | |||
+ | Pas difficile du tout. Maintenant, personnalisons quelques TRadiobuttons et TCheckbuttons. Les voici dans leur état « natif ». | ||
+ | |||
**You can customize the indicators so that they use your own customized graphics. At a minimum, you’ll need to have three images for each class. One for unselected, one for selected, and one for disabled. | **You can customize the indicators so that they use your own customized graphics. At a minimum, you’ll need to have three images for each class. One for unselected, one for selected, and one for disabled. | ||
Ligne 49: | Ligne 96: | ||
I used the shared module scheme in order to keep from having to declare a tonne of global variables. The shared module is an empty file in the project folder – that all modules can read and write to. The file can be named anything, as long as it has the extension of “.py”, and that you import it into any other Python files that will use it. By using the shared module scheme, it is much easier. Now that we have all of the Radiobutton images set into image objects, we then can create the element that we will use (below).** | I used the shared module scheme in order to keep from having to declare a tonne of global variables. The shared module is an empty file in the project folder – that all modules can read and write to. The file can be named anything, as long as it has the extension of “.py”, and that you import it into any other Python files that will use it. By using the shared module scheme, it is much easier. Now that we have all of the Radiobutton images set into image objects, we then can create the element that we will use (below).** | ||
+ | |||
+ | Vous pouvez personnaliser les indicateurs afin qu'ils utilisent vos propres éléments graphiques personnalisés. Au minimum, vous devrez disposer de trois images pour chaque classe. Une pour la non-sélection, | ||
+ | |||
+ | Voici une image de référence rapide des six indicateurs que j'ai utilisés pour personnaliser les TRadiobuttons et les TCheckbuttons. Rappelez-vous, | ||
+ | |||
+ | Nous devons maintenant coder le style et la disposition des éléments. | ||
+ | |||
+ | Tout d' | ||
+ | |||
+ | J'ai utilisé le schéma du module partagé afin de ne pas avoir à déclarer une tonne de variables globales. Le module partagé est un fichier vide dans le dossier du projet, ouvert en lecture et en écriture à tous les modules. Le fichier peut porter n' | ||
+ | |||
**Once you get used to the idea, it’s not that hard, but it is the first time. So we define a new element with element_create and give it a name ‘custom.RBindicator’. We declare the type of element, which is image, and then we define the image name for the unselected state. Then, we define the selected and disabled states, and assign the images to them. | **Once you get used to the idea, it’s not that hard, but it is the first time. So we define a new element with element_create and give it a name ‘custom.RBindicator’. We declare the type of element, which is image, and then we define the image name for the unselected state. Then, we define the selected and disabled states, and assign the images to them. | ||
Ligne 61: | Ligne 119: | ||
In wrapping up, I thought I’d leave you with a number of resources to help you out, if you become brave and try to create your own style sets. In a later article, I’ll show you how to create your own theme – once you’ve gotten the style sets for all the ttk widgets.** | In wrapping up, I thought I’d leave you with a number of resources to help you out, if you become brave and try to create your own style sets. In a later article, I’ll show you how to create your own theme – once you’ve gotten the style sets for all the ttk widgets.** | ||
+ | |||
+ | Une fois que vous vous serez habitué à l' | ||
+ | |||
+ | Enfin, nous devons créer le layout et remplacer l' | ||
+ | |||
+ | C'est tout pour les TRadiobuttons. Suivez les mêmes étapes pour les TCheckbuttons, | ||
+ | |||
+ | C'est assez intimidant la première ou la deuxième fois que vous le faites, mais cela devient plus facile au fur et à mesure. | ||
+ | |||
+ | Chaque widget a des éléments et des options différents que vous pouvez et devriez probablement envisager de régler. Une fois que vous avez un modèle pour les mises en page, cela devient beaucoup plus facile. | ||
+ | |||
+ | En conclusion, j'ai pensé vous laisser avec un certain nombre de ressources pour vous aider, si vous devenez courageux et essayez de créer vos propres ensembles de style. Dans un prochain article, je vous montrerai comment créer votre propre thème - une fois que vous aurez obtenu les jeux de styles pour tous les widgets ttk. | ||
+ | |||
**Given that there are so many options that so many don’t know about, I’m going to provide two generic links and a specific one. The first one is to the New Mexico Tech Tkinter 8.5 Manual. | **Given that there are so many options that so many don’t know about, I’m going to provide two generic links and a specific one. The first one is to the New Mexico Tech Tkinter 8.5 Manual. | ||
Ligne 72: | Ligne 143: | ||
(One word of warning. If you look back at the Button.label options, you will see one named ‘embossed’. I’ve NEVER been able to find out what this is supposed to do. It’s not in the documentation, | (One word of warning. If you look back at the Button.label options, you will see one named ‘embossed’. I’ve NEVER been able to find out what this is supposed to do. It’s not in the documentation, | ||
+ | |||
+ | Étant donné qu'il y a tant d' | ||
+ | https:// | ||
+ | |||
+ | Le deuxième est un bon point de départ pour la page du manuel « officiel » de la boîte à outils ttk, directement de source sûre chez le groupe tcl. C'est censé être ainsi : si ce n'est pas ici, c'est que ça ne peut pas être fait. | ||
+ | https:// | ||
+ | |||
+ | Enfin, je vais vous donner le lien vers la page « officielle » du manuel de ttk Button. Pour découvrir toutes les options et paramètres (et ce que beaucoup d' | ||
+ | https:// | ||
+ | |||
+ | (Un mot d' | ||
+ | |||
**I will leave you with a theme that is created in Python, not tcl. This is a port of the Plastik theme which is part of the ttkwidgets Python library, which, like most themes, is written in Tcl and is pretty difficult to port to Python unless you are familiar with both languages. You can get the Plastic-python file at | **I will leave you with a theme that is created in Python, not tcl. This is a port of the Plastik theme which is part of the ttkwidgets Python library, which, like most themes, is written in Tcl and is pretty difficult to port to Python unless you are familiar with both languages. You can get the Plastic-python file at | ||
Ligne 82: | Ligne 165: | ||
Until next time, as always; stay safe, healthy, positive and creative!** | Until next time, as always; stay safe, healthy, positive and creative!** | ||
+ | |||
+ | Je vous laisse avec un thème qui est créé en Python, pas en Tcl. C'est un portage du thème Plastik qui fait partie de la bibliothèque Python ttkwidgets, qui, comme la plupart des thèmes, est écrit en Tcl et est assez difficile à porter en Python à moins d' | ||
+ | https:// | ||
+ | |||
+ | Puisque j'ai mentionné le paquet ttkwidgets, vous pouvez l' | ||
+ | https:// | ||
+ | |||
+ | Suivez la documentation sur la façon de l' | ||
+ | |||
+ | Jusqu' | ||
issue188/python.1672742765.txt.gz · Dernière modification : 2023/01/03 11:46 de d52fr