issue149: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 | |||
issue149:python [2019/10/10 14:40] – auntiee | issue149:python [2019/10/10 16:14] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
De temps en temps, j'aide Don Rozenberg, le créateur de Page (un concepteur d' | De temps en temps, j'aide Don Rozenberg, le créateur de Page (un concepteur d' | ||
- | Si vous ne connaissez pas les gadgets de ttk, c'est un ensemble de gadgets complémentaires disponibles pour Tkinter dans la boîte à outils Tk, qui fait partie de Tcl. La boîte à outils Tk est disponible pour Perl et Ruby ainsi que pour Tcl et Python. La portion pour ttk de la boîte à outils donne des gadgets de remplacement pour beaucoup de gadgets Tk standards… | + | Si vous ne connaissez pas les gadgets de ttk, c'est un ensemble de gadgets complémentaires disponibles pour Tkinter dans la boîte à outils Tk, qui fait partie de Tcl. La boîte à outils Tk est disponible pour Perl et Ruby ainsi que pour Tcl et Python. La portion pour ttk de la boîte à outils donne des gadgets de remplacement pour beaucoup de gadgets Tk standards... |
**They pretty much act as the standard widgets do, they just have a different, more updated look to them (at least to some people). There are also preset styles that you can use that changes the look of them. On Linux machines, there are 4 pre-defined styles, named clam, alt, default and classic). On Windows machines, there are three others as well, called “winnative’, | **They pretty much act as the standard widgets do, they just have a different, more updated look to them (at least to some people). There are also preset styles that you can use that changes the look of them. On Linux machines, there are 4 pre-defined styles, named clam, alt, default and classic). On Windows machines, there are three others as well, called “winnative’, | ||
Ligne 13: | Ligne 13: | ||
Ils fonctionnent de façon assez similaire aux gadgets standards ; ils ont surtout un aspect différent, plus à jour (du moins selon certaines personnes). Ils disposent aussi de thèmes pré-réglés que vous pouvez utiliser pour changer leur aspect. Sur les machines Linux, il y a 4 styles prédéfinis, | Ils fonctionnent de façon assez similaire aux gadgets standards ; ils ont surtout un aspect différent, plus à jour (du moins selon certaines personnes). Ils disposent aussi de thèmes pré-réglés que vous pouvez utiliser pour changer leur aspect. Sur les machines Linux, il y a 4 styles prédéfinis, | ||
- | Quand je fais une interface utilisateur, | + | Quand je fais une interface utilisateur, |
**I know this graphic is mostly unreadable, but it is illustrative of the number of attributes that you can control for a standard button (on the left side) compared to the ttk button (on the right). Part of the discrepancy stems from the fact that the style controls most of the attributes that seem to be missing. In a good way, this is a good thing. On the other hand, since the style is “taking care of these attributes for you”, for the most part the style keeps you from making changes to what could normally be an important attribute when you are trying to “push the envelope” and make your GUI program look more modern than standard Tkinter widgets allow. | **I know this graphic is mostly unreadable, but it is illustrative of the number of attributes that you can control for a standard button (on the left side) compared to the ttk button (on the right). Part of the discrepancy stems from the fact that the style controls most of the attributes that seem to be missing. In a good way, this is a good thing. On the other hand, since the style is “taking care of these attributes for you”, for the most part the style keeps you from making changes to what could normally be an important attribute when you are trying to “push the envelope” and make your GUI program look more modern than standard Tkinter widgets allow. | ||
Ligne 19: | Ligne 19: | ||
While the above might dissuade many users from even trying ttk widgets, a larger number of users are overwhelmed by how hard it is to find really good documentation on the use and customization of ttk widgets. Even those sites on the Internet that touch on how to do it, only give a small amount of information and even then, there isn’t much about using ttk goodies in Page. So, I thought I’d try to fix this in some small way.** | While the above might dissuade many users from even trying ttk widgets, a larger number of users are overwhelmed by how hard it is to find really good documentation on the use and customization of ttk widgets. Even those sites on the Internet that touch on how to do it, only give a small amount of information and even then, there isn’t much about using ttk goodies in Page. So, I thought I’d try to fix this in some small way.** | ||
- | Je sais que cette image est à peu près illisible, mais elle illustre bien le nombre d' | + | Je sais que cette image est à peu près illisible, mais elle illustre bien le nombre d' |
Bien que cela puisse dissuader certains utilisateurs de donner une chance aux gadgets ttk, un grand nombre d' | Bien que cela puisse dissuader certains utilisateurs de donner une chance aux gadgets ttk, un grand nombre d' | ||
Ligne 67: | Ligne 67: | ||
Our code will be pretty minimal. We'll start with fleshing out the on_rbClick() function. This is a callback function that fires whenever the user clicks on one of the TRadiobuttons. Code is shown on the next page, top right.** | Our code will be pretty minimal. We'll start with fleshing out the on_rbClick() function. This is a callback function that fires whenever the user clicks on one of the TRadiobuttons. Code is shown on the next page, top right.** | ||
- | Si tout s'est bien déroulé pendant la création du GUI, Page devrait avoir créé pour vous les fonctions suivantes… | + | Si tout s'est bien déroulé pendant la création du GUI, Page devrait avoir créé pour vous les fonctions suivantes |
set_Tk_var() | set_Tk_var() | ||
Ligne 84: | Ligne 84: | ||
Next we repeat the operation in the print statement that gets the value of that TRadiobutton and finally, we tell ttk to use the correct style to draw the widgets. This happens immediately.** | Next we repeat the operation in the print statement that gets the value of that TRadiobutton and finally, we tell ttk to use the correct style to draw the widgets. This happens immediately.** | ||
- | Page a incorporé les deux premières déclarations (print(...) et sys.stdout.flush()) à votre place. Ainsi, la première ligne de notre code imprime la valeur du TRadiobutton que nous avons entrée dans l' | + | Page a incorporé les deux premières déclarations (print(...) et sys.stdout.flush()) à votre place. Ainsi, la première ligne de notre code imprime la valeur du TRadiobutton que nous avons entrée dans l' |
(' | (' | ||
Ligne 103: | Ligne 103: | ||
setup_styles()** | setup_styles()** | ||
- | Maintenant, nous incorporons l' | + | Maintenant, nous incorporons l' |
def on_btnExit(): | def on_btnExit(): | ||
print(' | print(' | ||
Ligne 157: | Ligne 156: | ||
cntr += 1** | cntr += 1** | ||
| | ||
- | Maintenant, nous créons une fonction dans notre fonction qui efface les champs de texte et désactive les 7 boutons radio. Je suis sûr que vous comprenez pourquoi nous effaçons les champs de texte, et la raison pour laquelle nous désactivons tous les boutons gadgets TRadiobuttons à cet endroit vient du fait que, si nous fonctionnons sous Linux, l' | + | Maintenant, nous créons une fonction dans notre fonction qui efface les champs de texte et désactive les 7 boutons radio. Je suis sûr que vous comprenez pourquoi nous effaçons les champs de texte, et la raison pour laquelle nous désactivons tous les boutons gadgets TRadiobuttons à cet endroit vient du fait que, si nous fonctionnons sous Linux, l' |
clear_radio_buttons() | clear_radio_buttons() | ||
Ligne 176: | Ligne 175: | ||
w.TProgressbar1.start()** | w.TProgressbar1.start()** | ||
- | Nous utiliserons une simple boucle for pour le faire. Nous utiliserons, | + | Nous utiliserons une simple boucle for pour le faire. Nous utiliserons, |
Enfin, nous paramétrerons la barre TProgress pour qu' | Enfin, nous paramétrerons la barre TProgress pour qu' | ||
Ligne 192: | Ligne 191: | ||
That was easy and pretty much painless. As always, I've put all the code up on pastebin at the following links...** | That was easy and pretty much painless. As always, I've put all the code up on pastebin at the following links...** | ||
- | Ça y est. Sauvegardez votre programme et vous pouvez le lancer dans Python. Maintenant, chaque fois que vous voulez utiliser des gadgets ttk dans votre GUI, vous savez à quoi ils ressembleront quel que soit le style et une fois que vous en avez choisi un à votre goût, vous pouvez mettre les lignes suivantes quelque part dans la fonction init() (après les quatre premières lignes)… | + | Ça y est. Sauvegardez votre programme et vous pouvez le lancer dans Python. Maintenant, chaque fois que vous voulez utiliser des gadgets ttk dans votre GUI, vous savez à quoi ils ressembleront quel que soit le style et une fois que vous en avez choisi un à votre goût, vous pouvez mettre les lignes suivantes quelque part dans la fonction init() (après les quatre premières lignes) |
style = ttk.Style() | style = ttk.Style() | ||
style.theme_use(‘votre_style_ici’) | style.theme_use(‘votre_style_ici’) | ||
| | ||
- | C' | + | C' |
**ttkdemo.tcl - https:// | **ttkdemo.tcl - https:// |
issue149/python.1570711258.txt.gz · Dernière modification : 2019/10/10 14:40 de auntiee