issue193: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édente | |||
issue193:python [2023/05/29 08:47] – d52fr | issue193:python [2023/05/31 12:15] (Version actuelle) – auntiee | ||
---|---|---|---|
Ligne 30: | Ligne 30: | ||
So the first thing that needs to happen is to create an object that inherits from the ttk.Style base object. After many hours of struggling to come up with a name for my version of the object, I finally settled on “style”. Pretty cool, huh? Anyway, that joke probably fell flat, so we’ll move on.** | So the first thing that needs to happen is to create an object that inherits from the ttk.Style base object. After many hours of struggling to come up with a name for my version of the object, I finally settled on “style”. Pretty cool, huh? Anyway, that joke probably fell flat, so we’ll move on.** | ||
- | J' | + | J' |
- | Le TNotebook dispose d'une option peu connue (enfin, probablement peu connue de la plupart des programmeurs Tkinter) qui permet au programmeur de définir la position de la partie Tab du widget TNotebook. Elle fait partie des options de ttk Style. Malheureusement, | + | Le TNotebook dispose d'une option peu connue (enfin, probablement peu connue de la plupart des programmeurs Tkinter) qui permet au programmeur de définir la position de la partie Tab du widget TNotebook. Elle fait partie des options de ttk Style. Malheureusement, |
- | La première chose à faire est donc de créer un objet qui hérite de l' | + | La première chose à faire est donc de créer un objet qui hérite de l' |
Ligne 49: | Ligne 49: | ||
The next function that we will take a look at is the callback function that is called whenever a TRadiobutton is clicked. Just so you know, all the TRadiobuttons have the same callback and the values of the TRadiobuttons are set 1 to 12. This makes it easy to use an if tree. It would be just as easy to use the switch case tree, but since that is available only from 3.10 forward, I decided to stick with the if tree (see code right).** | The next function that we will take a look at is the callback function that is called whenever a TRadiobutton is clicked. Just so you know, all the TRadiobuttons have the same callback and the values of the TRadiobuttons are set 1 to 12. This makes it easy to use an if tree. It would be just as easy to use the switch case tree, but since that is available only from 3.10 forward, I decided to stick with the if tree (see code right).** | ||
- | La partie suivante de la fonction n'est probablement pas utile pour ce programme | + | La partie suivante de la fonction n'est probablement pas utile pour ce programme-ci, puisque toutes les décisions relatives à la position sont fournies par les TRadiobuttons. Cependant, si vous avez l' |
- | La liste des positions est fournie pour vérifier que le paramètre passé est bien l'une des positions « légales ». Nous vérifions si le paramètre fait partie de la liste des positions, et si c'est le cas, nous utilisons la commande Style.configure. La syntaxe est la suivante | + | La liste des positions est fournie pour vérifier que le paramètre passé est bien l'une des positions « légales ». Nous vérifions si le paramètre fait partie de la liste des positions et, si c'est le cas, nous utilisons la commande Style.configure. La syntaxe est la suivante |
style.configure(TWidget name, StyleOption = Value, …) | style.configure(TWidget name, StyleOption = Value, …) | ||
Ligne 59: | Ligne 59: | ||
C'est là toute la magie qui a rarement été documentée. | C'est là toute la magie qui a rarement été documentée. | ||
- | La fonction suivante que nous allons examiner est la fonction de rappel qui est appelée chaque fois qu'un TRadiobutton | + | La fonction suivante que nous allons examiner est la fonction de rappel qui est appelée chaque fois qu'on clique sur TRadiobutton. Pour votre information, |
Ligne 93: | Ligne 93: | ||
**The first few lines simply set up some general styling things (which we’ll discuss next month) and calls an imported Python module that I created and named mystyles_dark. This was an experiment I played around with back in December 2022. The idea was to create a Python based Theme for Tkinter programs. If you remember, a ttk Theme is simply a collection of styles that apply to various ttk widgets. I never got around to finishing that project, since once I got the basics of getting the styles for various widgets going, I then put the Python file on the back burner and dived head first into writing a true Tcl/Tk theme in Tcl. (That was an experience, let me tell you! Well, actually that story is going in a blog on my website.) Anyway, I digress. The Python style module has only one function, which is create_styles() which handles all of the stylings. It requires the style object (in this case sty (actually a better name than style, huh? Less to type!)). By calling it, all the widgets it has code for (most of the ttk library) is now styled to a fairly dark color. I then grab the background color from the Python styling library and assign that to a global variable (background1). Then I call the TNotebook Tab styling routine. The frames that make up the “pages” of the TNotebook, are coloured by calling the function color_notebook_pages(). I then set the background through style.configure to be the same background as the rest of the project. All the labels, since I mix Tk Labels and ttk.TLabels on the pages of the TNotebook need to be set to proper background and foreground colors, which is what the function fix_labels() does. Finally, I make sure that the Tabs positions are set to the default position and set the title for the project and center it into the screen (code shown top right).** | **The first few lines simply set up some general styling things (which we’ll discuss next month) and calls an imported Python module that I created and named mystyles_dark. This was an experiment I played around with back in December 2022. The idea was to create a Python based Theme for Tkinter programs. If you remember, a ttk Theme is simply a collection of styles that apply to various ttk widgets. I never got around to finishing that project, since once I got the basics of getting the styles for various widgets going, I then put the Python file on the back burner and dived head first into writing a true Tcl/Tk theme in Tcl. (That was an experience, let me tell you! Well, actually that story is going in a blog on my website.) Anyway, I digress. The Python style module has only one function, which is create_styles() which handles all of the stylings. It requires the style object (in this case sty (actually a better name than style, huh? Less to type!)). By calling it, all the widgets it has code for (most of the ttk library) is now styled to a fairly dark color. I then grab the background color from the Python styling library and assign that to a global variable (background1). Then I call the TNotebook Tab styling routine. The frames that make up the “pages” of the TNotebook, are coloured by calling the function color_notebook_pages(). I then set the background through style.configure to be the same background as the rest of the project. All the labels, since I mix Tk Labels and ttk.TLabels on the pages of the TNotebook need to be set to proper background and foreground colors, which is what the function fix_labels() does. Finally, I make sure that the Tabs positions are set to the default position and set the title for the project and center it into the screen (code shown top right).** | ||
- | Les premières lignes mettent simplement en place quelques éléments de style généraux (dont nous parlerons le mois prochain) et appellent un module Python importé que j'ai créé et nommé mystyles_dark. Il s'agit d'une expérience avec laquelle j'ai joué en décembre 2022. L' | + | Les premières lignes mettent simplement en place quelques éléments de style généraux (dont nous parlerons le mois prochain) et appellent un module Python importé que j'ai créé et nommé mystyles_dark. Il s'agit d'une expérience avec laquelle j'ai joué en décembre 2022. L' |
Ligne 106: | Ligne 106: | ||
NOTE TARDIVE : | NOTE TARDIVE : | ||
- | Après avoir écrit cet article, je suis retourné voir le module mystyles.dark. J'ai dit qu'à peu près dès que je l' | + | Après avoir écrit cet article, je suis retourné voir le module mystyles.dark. J'ai dit qu'à peu près dès que je l' |
issue193/python.1685342850.txt.gz · Dernière modification : 2023/05/29 08:47 de d52fr