Outils pour utilisateurs

Outils du site


issue137:python

Ceci est une ancienne révision du document !


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.)

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.

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.

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.

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!

issue137/python.1538411059.txt.gz · Dernière modification : 2018/10/01 18:24 de auntiee