issue179:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue179:python [2022/03/27 14:55] – créée auntiee | issue179:python [2022/03/30 17:43] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | As most of you know, I work fairly closely with Don Rozenberg on his free GUI designer for Python programs called PAGE. Just the other day, I received the following message from SourceForge: | + | **As most of you know, I work fairly closely with Don Rozenberg on his free GUI designer for Python programs called PAGE. Just the other day, I received the following message from SourceForge: |
“Congratulations! PAGE has just been recognized with the following awards by SourceForge: | “Congratulations! PAGE has just been recognized with the following awards by SourceForge: | ||
Ligne 10: | Ligne 10: | ||
These honors are awarded only to select projects that have reached significant milestones in terms of downloads and user engagement from the SourceForge community. | These honors are awarded only to select projects that have reached significant milestones in terms of downloads and user engagement from the SourceForge community. | ||
- | This is a big achievement, | + | This is a big achievement, |
- | To celebrate this accomplishment, | + | Comme la plupart d' |
+ | |||
+ | « Félicitations ! PAGE vient d' | ||
+ | |||
+ | Leader de la communauté | ||
+ | Choix de la communauté | ||
+ | Excellence de l'Open Source | ||
+ | Favoris de SourceForge | ||
+ | |||
+ | Ces distinctions sont attribuées uniquement à des projets sélectionnés qui ont atteint des étapes importantes en termes de téléchargements et d' | ||
+ | |||
+ | C'est une grande réussite, car votre projet s'est qualifié pour ces prix parmi plus de 500 000 projets Open Source sur SourceForge. SourceForge compte près de 30 millions d' | ||
+ | |||
+ | |||
+ | **To celebrate this accomplishment, | ||
The first tip concerns enhancing the Tk Checkbutton. We all know what a “regular” checkbutton looks like. | The first tip concerns enhancing the Tk Checkbutton. We all know what a “regular” checkbutton looks like. | ||
+ | |||
While this is an easy widget to use to represent a many-of-many set of options, this is pretty much an old style visual widget. But what about this? | While this is an easy widget to use to represent a many-of-many set of options, this is pretty much an old style visual widget. But what about this? | ||
This is the image of a customized Checkbutton in the off state, and here is the same Checkbutton in the on state. | This is the image of a customized Checkbutton in the off state, and here is the same Checkbutton in the on state. | ||
+ | |||
It’s really easy to create a Checkbutton that looks and works like this using Tkinter and especially in PAGE. First, you need to have the two graphic images you want to use to represent the selected and unselected states. I went to my standard goto website for graphics, openclipart.org. I did a simple search for “switch” and this was one of the options. | It’s really easy to create a Checkbutton that looks and works like this using Tkinter and especially in PAGE. First, you need to have the two graphic images you want to use to represent the selected and unselected states. I went to my standard goto website for graphics, openclipart.org. I did a simple search for “switch” and this was one of the options. | ||
+ | |||
https:// | https:// | ||
- | I chose the small .png version, downloaded it and then used Gimp to cut each one out and saved them as separate .png files. I copied them into an images folder inside my project. | + | I chose the small .png version, downloaded it and then used Gimp to cut each one out and saved them as separate .png files. I copied them into an images folder inside my project.** |
+ | |||
+ | Pour fêter cette récompense, | ||
+ | |||
+ | La première astuce concerne l' | ||
+ | |||
+ | Bien qu'il s' | ||
+ | |||
+ | Voici l' | ||
+ | |||
+ | Il est très facile de créer un bouton de contrôle qui ressemble et fonctionne comme celui-ci en utilisant Tkinter, surtout dans PAGE. D' | ||
+ | |||
+ | https:// | ||
+ | |||
+ | J'ai choisi la petite version .png, je l'ai téléchargée, | ||
- | Next, I simply placed a standard Tk Checkbutton on the Toplevel form, next to a few other Checkbuttons and I set the attributes using the PAGE Attribute Editor (see table, previous page, bottom right). | + | **Next, I simply placed a standard Tk Checkbutton on the Toplevel form, next to a few other Checkbuttons and I set the attributes using the PAGE Attribute Editor (see table, previous page, bottom right). |
When the program is run, the Custom checkbutton will act as a toggle switch. | When the program is run, the Custom checkbutton will act as a toggle switch. | ||
Ligne 29: | Ligne 61: | ||
There is one other trick that can be used with the Checkbutton, | There is one other trick that can be used with the Checkbutton, | ||
And this is the selected state. | And this is the selected state. | ||
- | You can pick to have a color in the unselected state or not. I chose to use coral for the unselected and limegreen for the selected color. Just like the Checkbutton, | ||
- | The next trick is to modify | + | You can pick to have a color in the unselected state or not. I chose to use coral for the unselected and limegreen for the selected color. Just like the Checkbutton, |
- | As I’ve stated many times in the past, I am not an artist in any way, shape or form. I threw together the following images to help show the process. | + | The next trick is to modify the standard Tk Radiobutton to provide a custom indicator dot. As with the Checkbutton trick, you will need two graphics. One for the indicator when it is not selected and one for when it is selected.** |
+ | |||
+ | Ensuite, j'ai simplement placé un bouton à cocher Tk standard sur le formulaire Toplevel, à côté de quelques autres boutons à cocher et j'ai défini les attributs à l'aide de l' | ||
+ | |||
+ | Lorsque le programme est exécuté, le bouton à cocher personnalisé agira comme un interrupteur à bascule. | ||
+ | |||
+ | Il existe une autre astuce qui peut être utilisée avec le bouton à cocher, et aucune image n'est nécessaire. Elle transforme le bouton à cocher en un bouton « à verrouillage ». Lorsqu' | ||
+ | |||
+ | Et voici l' | ||
+ | |||
+ | Vous pouvez choisir d' | ||
+ | |||
+ | L' | ||
+ | |||
+ | |||
+ | **As I’ve stated many times in the past, I am not an artist in any way, shape or form. I threw together the following images to help show the process. | ||
First the unselected image. It’s simply a circle. | First the unselected image. It’s simply a circle. | ||
Ligne 43: | Ligne 89: | ||
The only thing that is a downside for this trick is that (as you can see in the image below) the Radiobutton goes to a sunken relief. As far as I can tell, there’s nothing that we can do about that (but you know I won’t give up trying). | The only thing that is a downside for this trick is that (as you can see in the image below) the Radiobutton goes to a sunken relief. As far as I can tell, there’s nothing that we can do about that (but you know I won’t give up trying). | ||
- | So here is what the full demo project looks like (next page, top right). | + | So here is what the full demo project looks like (next page, top right).** |
- | As to the code, it’s really very simple. | + | Comme je l'ai dit à plusieurs reprises dans le passé, je ne suis pas un artiste de quelque manière que ce soit. J'ai rassemblé les images suivantes pour aider à montrer le processus. |
+ | |||
+ | D' | ||
+ | |||
+ | Et l' | ||
+ | |||
+ | Comme nous l' | ||
+ | |||
+ | La seule chose qui est un inconvénient pour cette astuce est que (comme vous pouvez le voir dans l' | ||
+ | |||
+ | Voici donc à quoi ressemble le projet de démonstration complet (page suivante, en haut à droite). | ||
+ | |||
+ | |||
+ | **As to the code, it’s really very simple. | ||
def startup(): | def startup(): | ||
Ligne 73: | Ligne 132: | ||
f' | f' | ||
+ | |||
+ | )** | ||
+ | | ||
+ | Quant au code, il est vraiment très simple. | ||
+ | |||
+ | def startup() : | ||
+ | |||
+ | _w1.Checkbutton1.invoke() | ||
+ | |||
+ | _w1.Radiobutton1.invoke() | ||
+ | |||
+ | _w1.Radiobutton3.invoke() | ||
+ | |||
+ | |||
+ | La fonction de démarrage appelle la méthode .invoke du premier bouton à cocher et des premier et troisième boutons radios. La méthode invoke fait croire au programme qu'il y a eu un clic de souris sur le widget, ce qui appelle alors la fonction de rappel de la commande associée. Je voulais que le premier widget de chaque groupe soit sélectionné au démarrage. | ||
+ | |||
+ | def on_chkbtnClick(*args) : | ||
+ | |||
+ | status_list = [' | ||
+ | |||
+ | cb1 = _w1.che47.get() | ||
+ | |||
+ | cb2 = _w1.che48.get() | ||
+ | |||
+ | cb3 = _w1.che49.get() | ||
+ | |||
+ | cb4 = _w1.che50.get() | ||
+ | |||
+ | _w1.CheckDisplay.set( | ||
+ | |||
+ | f' | ||
) | ) | ||
+ | | ||
- | The callback for the Checkbuttons is really simple. The first thing that gets done is to create a very simple list with the text values ‘Off’ and ‘On’ which will be shown as part of a string that will be sent to the display label. Next each of the variables for the Checkbuttons show 0 for unselected and 1 for selected. Those values work nicely as a “pointer” into the list for the display string. Finally we create the string and send it to the label to be displayed. | + | **The callback for the Checkbuttons is really simple. The first thing that gets done is to create a very simple list with the text values ‘Off’ and ‘On’ which will be shown as part of a string that will be sent to the display label. Next each of the variables for the Checkbuttons show 0 for unselected and 1 for selected. Those values work nicely as a “pointer” into the list for the display string. Finally we create the string and send it to the label to be displayed. |
The next two callbacks are for when the Radibutton groups are clicked. The first two (top two) Radiobuttons on the form are handled by the top function and the bottom two custom Radiobuttons are handled by the second function. | The next two callbacks are for when the Radibutton groups are clicked. The first two (top two) Radiobuttons on the form are handled by the top function and the bottom two custom Radiobuttons are handled by the second function. | ||
Ligne 88: | Ligne 179: | ||
def on_rbtnClick2(*args): | def on_rbtnClick2(*args): | ||
+ | |||
+ | which2 = _w1.selectedButton2.get() | ||
+ | |||
+ | _w1.RadioDisplay.set(f' | ||
+ | | ||
+ | Le rappel des boutons de contrôle est vraiment simple. La première chose qui est faite est de créer une liste très simple avec les valeurs de texte « Off » et « On » qui seront affichées dans le cadre d'une chaîne qui sera envoyée à l' | ||
+ | |||
+ | Les deux rappels suivants s' | ||
+ | |||
+ | def on_rbtnClick1(*args) : | ||
+ | |||
+ | which1 = _w1.selectedButton.get() | ||
+ | |||
+ | _w1.RadioDisplay.set(f' | ||
+ | |||
+ | |||
+ | def on_rbtnClick2(*args) : | ||
which2 = _w1.selectedButton2.get() | which2 = _w1.selectedButton2.get() | ||
_w1.RadioDisplay.set(f' | _w1.RadioDisplay.set(f' | ||
+ | | ||
- | That’s all I have time for this month. Remember these tips are for “standard” Tk widgets. Yes, there are ttk widgets that can have styles and themes applied to them. The problem with styles and themes are: | + | **That’s all I have time for this month. Remember these tips are for “standard” Tk widgets. Yes, there are ttk widgets that can have styles and themes applied to them. The problem with styles and themes are: |
• Styles and themes are poorly documented | • Styles and themes are poorly documented | ||
Ligne 102: | Ligne 211: | ||
The PAGE source (version 7.3) and the Python code are all available on my repository. | The PAGE source (version 7.3) and the Python code are all available on my repository. | ||
- | Until next time, as always; stay safe, healthy, positive and creative! | + | Until next time, as always; stay safe, healthy, positive and creative!** |
+ | |||
+ | C'est tout ce que j'ai le temps de faire ce mois-ci. Rappelez-vous que ces conseils concernent les widgets Tk « standard ». Oui, il existe les widgets ttk auxquels on peut appliquer des styles et des thèmes. Le problème avec les styles et les thèmes est que : | ||
+ | |||
+ | - Les styles et les thèmes sont mal documentés. | ||
+ | - Les styles et les thèmes nécessitent une programmation spéciale en Tcl/Tk. | ||
+ | - Une grande partie de la documentation sur les styles et les thèmes est incomplète. | ||
+ | - ET (d' | ||
+ | |||
+ | La source PAGE (version 7.3) et le code Python sont tous disponibles sur mon dépôt. Vous pouvez le trouver à https:// | ||
+ | |||
+ | Jusqu' |
issue179/python.1648385709.txt.gz · Dernière modification : 2022/03/27 14:55 de auntiee