[Tutor] Shorten Code

Mic o0MB0o at hotmail.se
Tue Nov 22 20:41:19 CET 2011

> Button1 is supposed to represent chair one in the train.

>So call it chair_1 or put it in a list called chairs
>so that you can access them as chairs[0] or whatever.
>But get a name that reflects what its actually used for.

Yes, perhaps that is a good way to go. I didn't think about that.

> at the top of my email, I am writing a larger program. This program is
> supposed to be a GUI  online booking program for train tickets.

>OK, That's a pity.
>A Tkinter program is never going to be an online GUI, it only works on
>the desktop. For that you need to use HTML5/Flash/Javascript/Java etc.
>And its all a lot more messy.

No, I didn't mean that it have to work online. It is just fine if it works 
on the desktop.
I can only imagine how much more complicated things would be then. But if I 
understood it correctly,
with the help and information I got from you in this mail and in your 
previous mail, I can manage to
solve my problems? It is a bit hard right now to understand, because I am 
unfamiliar with using tuples/lists
and data tables. I will do my best to get it to work.

>> However, I understand if you don't have time to answer these probably
>> stupid and simple questions, I am still  grateful for your previous 
>> answers!

>They are neither simple nor stupid, they are very sensible questions and
>you are tackling a significant program. Sadly I don't think your
>approach will work for an 0nline solution (ie a web based one).

I just got my program to work today, but I want to shorten the code
using your suggestions in this and your previous email. I still find this 
to do because that way of thinking is completely new to me. I have one of 
these functions
below for each chair. I just want to use one instead of so many functions. 
That is why I am trying to understand and
implement your suggestions.

def chair1_clicked(self):
       """This method runs if chair one is clicked"""

       def change_chair1_value():
           global chair1_value
           button2_value=not chair1_value

       chair1_clicked ()

       if chair_value:


           def chair_color_red():
               global chair1_color

           os.remove ("Hamburg_Dortmund20_00")

           def chair1_color_green():
               global chair1_color

More information about the Tutor mailing list