Outils pour utilisateurs

Outils du site


issue137:python

As I sit here in the wee hours (3:30 am) of the morning, it is early September, 2018. We are right in the middle of hurricane season. I was about to say “in Texas”, but it is just about anywhere in the northern hemisphere in the “tropical” regions within about 400 miles from a coastal area. We fall into the “Atlantic” area, so our hurricane season runs from June 1st to November 30th. When I was young, we already had our preparations ready long before the end of May. This included getting batteries for the transistor radios, creating our hurricane box stocked with candles, canned food, duct tape, flashlights, bottled water, transistor radios, batteries, and more. Of course, when I was young, the rainbows were in black and white and we had to watch television by candlelight because there wasn't any electricity. (Please think about it for a minute…it WILL make sense.)

Alors que je suis assis ici aux petites heures (3 h 30) du matin, nous sommes au début de septembre 2018. Nous sommes en pleine saison des ouragans. J'allais dire « au Texas », mais c'est à peu près n'importe où dans l'hémisphère nord, dans les régions « tropicales » à environ 400 miles d'une zone côtière. Nous sommes dans la zone « Atlantique » et la saison des ouragans s'y étend du 1er juin au 30 novembre.

Quand j'étais jeune, nos préparatifs étaient déjà en place bien avant la fin mai. Cela comprenait l'achat de piles pour les radios à transistors, la création de notre boîte à ouragan remplie de bougies, d'aliments en conserve, de ruban adhésif en toile, de lampes de poche, de bouteilles d'eau, de radios à transistors, de piles et plus encore. Bien sûr, quand j'étais jeune, les arcs-en-ciel étaient en noir et blanc et nous devions regarder la télévision à la chandelle parce qu'il n'y avait pas d'électricité. (Pensez-y un instant… cela aura du sens.)

Why am I holding forth on hurricanes and when I was young? I'm not really sure, but it seemed like a good idea at the time, and it might be a good way to segue into our discussion for this month. I was taught a long time ago that “If you give a man a fish, he will be fed for a day. If, however, you teach a man to fish, he will be fed for the rest of his life”. This is a maxim that I have tried to apply to my life as long as I can remember. I guess that I'm a frustrated teacher, trapped in the body of a stand-up comedian, trapped in the body of a mediocre musician, trapped in the body of a programmer. My love of teaching things to people is why I started this almost monthly journey. I received an email from a beginner programmer who was reading a tutorial I had written for Don Rozenberg that has been included in the last few versions of Page. He was getting an error that he wasn't able to figure out, and asked Don for help. Since I had written the tutorial and the source code, Don passed it on to me. His problem was that when he recreated one of the examples in the tutorial and ran it, he was getting a “NameError: name 'che39' is not defined” error. Being a beginner Python user, and at the same time, a new Page user, he didn't understand what the issue was. The Python error message didn't mean anything to him.

Pourquoi suis-je en train de parler d'ouragans et de quand j'étais jeune ? Je n'en suis pas vraiment sûr, mais cela m'a semblé être une bonne idée à ce moment-là, et ce pourrait être un bon moyen de faire une transition vers notre discussion de ce mois-ci.

On m'a appris il y a longtemps que « Si vous donnez un poisson à un homme, il sera nourri pour un jour. Si, à la place, vous lui apprenez à pêcher, il sera nourri pour le reste de sa vie ». C'est une maxime que j'ai essayé d'appliquer tout au long de ma vie, d'aussi loin que je puisse me souvenir. Je suppose que je suis un professeur frustré, piégé dans le corps d'un comédien, piégé dans le corps d'un musicien médiocre, piégé dans le corps d'un programmeur. C'est parce que j'aime enseigner des choses aux gens que j'ai amorcé ce voyage presque mensuel.

J'ai reçu un courriel d'un programmeur débutant qui lisait un tutoriel que j'avais écrit pour Don Rozenberg et qui est inclus dans les dernières versions de Page. Il obtenait une erreur qu'il n'arrivait pas à comprendre, et il a demandé de l'aide à Don. Comme j'avais écrit le tutoriel et le code source, Don me l'a transmis.

Son problème était que lorsqu'il a recréé l'un des exemples du tutoriel et l'a exécuté, il obtenait une erreur « NameError : name 'che39' is not defined ». Étant un utilisateur débutant de Python, et en même temps, un nouvel utilisateur de Page, il ne comprenait pas le problème. Le message d'erreur Python ne signifiait rien pour lui.

This is a typical issue for new users. Especially when trying to follow a tutorial that someone wrote. The specific line in his code was: if che39.get() == “1”: I responded to him that the issue is due to his Python script using a variable name in a comparison operation that didn't exist, especially one that has a method attached. I suggested that he either had a typo in his code or missed a step in the design section of the tutorial. I gave him a few places to look for the problem. The first was to open the project in Page and check the specific CheckButton widget attributes. In this case, there is an attribute for the variable that allows the user to check, using the .get() method, the checked status of the widget. This is where the 'che39' came from. Page provides a default variable for this. The tutorial said to make sure that this variable attribute be set to 'che39', since sometimes Page comes with a different one. When he recreated the project, he could have accidentally put in something different or missed that part all together. It happens to all of us from time to time. As it turns out, this was where the error was, but he put the variable name in the wrong spot in the Attributes Editor. He put it under the text variable entry box, not the variable box. Again, a common mistake. I know I have done it more times that I want to admit. Once the new user found the cause of this problem, he stumbled across another one. This time, it wasn’t his fault. A few other Page users discovered this a number of months ago, but I was never able to recreate it.

C'est un problème typique pour les nouveaux utilisateurs. Surtout quand on essaie de suivre un tutoriel que quelqu'un a écrit.

La ligne en question dans son code était :

if che39.get() == “1”:

Je lui ai répondu que le problème est dû à son script Python qui utilisait un nom de variable qui n'existait pas dans une opération de comparaison, surtout une employant une méthode. J'ai suggéré qu'il avait une faute de frappe dans son code ou qu'il avait manqué une étape dans la section de conception du tutoriel. Je lui ai donné quelques pistes pour chercher le problème. La première était d'ouvrir le projet dans Page et de vérifier les attributs spécifiques du widget CheckButton. Dans ce cas, il y a un attribut pour la variable qui permet à l'utilisateur de vérifier l'état du widget en utilisant la méthode .get(). C'est de là que vient le « che39 ». Page fournit une variable par défaut pour cela. Le tutoriel a dit de s'assurer que cet attribut de variable soit bien défini sur « che39 », puisque parfois Page est livré avec un autre attribut. Lorsqu'il a recréé le projet, il aurait pu mettre quelque chose de différent par accident ou manquer cette partie. Ça nous arrive à tous de temps en temps.

Il s'avère que c'est là que se trouvait l'erreur, mais il a mis le nom de la variable au mauvais endroit dans l'éditeur d'attributs. Il l'a mis sous la zone de saisie de la variable texte, pas sous la zone variable. Encore une fois, une erreur courante. Je sais que je l'ai faite bien plus de fois que je veux l'avouer.

Quand le nouvel utilisateur a trouvé la cause de ce problème, il est tombé sur un autre. Cette fois, ce n'était pas de sa faute. Quelques autres utilisateurs de Page l'ont découvert il y a quelques mois, mais je n'ai jamais été capable de le recréer.

It seems that if you use are using Python 3.x and use a LabelFrame, SOMETIMES some of the widgets you put inside of it will end up looking compressed, somewhat like a squished car. Take a look at the sample I wrote to demonstrate this issue: That really doesn’t look like something you want to put out into the world as a GUI. It’s not a fault of Page, and it’s not the fault of the person who created the GUI. It works just fine under Python 2.x, which is why I couldn’t reproduce the issue for the longest time. I had seen an issue posted on the Page discussion page about this months ago, and suggested to the user that they try to use the absolute positioning mode when designing his GUI. It turns out that this actually does work. However, there are issues with this. In the absolute position mode, when you resize the GUI form in the run mode, none of the widgets will resize themselves. This is, again, not really something that you want your end users to experience. The image below, however shows that my suggestion, does work.

Il semble que si vous utilisez Python 3.x et un LabelFrame, PARFOIS certains des widgets que vous mettez à l'intérieur finiront par avoir l'air compressés, comme une voiture écrasée. Jetez un coup d'œil à l'exemple que j'ai écrit pour illustrer ce problème :

Cela ne ressemble vraiment pas à quelque chose que vous voulez publier en tant qu'interface graphique. Ce n'est pas une faute de Page et ce n'est pas la faute de la personne qui a créé l'interface graphique. Il fonctionne très bien sous Python 2.x et c'est pourquoi je n'ai pas pu dupliquer le problème pendant longtemps.

J'avais vu un problème affiché sur la page de discussion de Page à ce sujet il y a des mois, et j'ai suggéré à l'utilisateur d'essayer d'utiliser le mode de positionnement absolu lors de la conception de son interface graphique. Il s'avère que cela fonctionne vraiment. Cependant, il y a des problèmes à ce sujet. En mode position absolue, lorsque vous redimensionnez le formulaire GUI en mode exécution, aucun des widgets ne se redimensionnera de lui-même. Encore une fois, ce n'est pas vraiment quelque chose que vous voulez que vos utilisateurs finaux perçoivent. L'image ci-dessous, cependant, montre que ma suggestion fonctionne.

Don had been aware of it for a little while, but was unable to explain what was happening. It turns out that it’s an issue with the actual TCL/TK widget, not even the Python Tkinter library. He had tried many things, thinking that it was something he had done. I just received word last night that there is a little documented flag for the widget that seems to fix the issue, and is actually marked (in the TCL documentation) that the flag “is probably not very useful”. Funny how an off-handed comment in documentation can make so much difference. Anyway, Don and I are testing the fix now and we’ll see what happens. Well, the old medical issues have raised their ugly heads and my medication is starting to make me sleepy again. I hate to have to do it, but I’ll close for this month. If everything works out like I am hoping, I’ll have something fun for you next month. Until then, have fun!

Don était au courant depuis quelque temps, mais il était incapable d'expliquer ce qui se passait. Il s'avère que c'est un problème avec le widget TCL/TK, pas du tout avec la bibliothèque Python Tkinter. Il avait essayé beaucoup de procédés, pensant que c'était quelque chose qu'il avait fait. J'ai appris hier soir qu'il y a un petit avertissement documenté pour le widget qui semble résoudre le problème, et il est en fait annoté (dans la documentation TCL) que cet avertissement « n'est probablement pas très utile ». C'est drôle comme un commentaire maladroit dans la documentation peut faire toute la différence.

Quoi qu'il en soit, Don et moi testons la solution maintenant et nous verrons ce qui se passera.

Eh bien, les vieux soucis médicaux refont leur apparition et mes médicaments commencent à nouveau à me rendre somnolent. Je déteste avoir à le faire, mais je conclus pour ce mois-ci. Si tout se passe comme je l'espère, je vous présenterai quelque chose de divertissant le mois prochain.

D'ici là, amusez-vous bien !

issue137/python.txt · Dernière modification : 2018/10/19 14:51 de andre_domenech