[Tutor] Shortening the code

Mic o0MB0o at hotmail.se
Tue Nov 22 22:17:18 CET 2011


>OK, So I'll guess you want a desktop program that eventually sends
>commands to an online service?
>If so thats a lot easier to do with Tkinter... :-)

Well, it is enough if the program can run on my desktop. However, there are
courses about learning how to make programs like these online, but I feel
like that is too hard for me at the moment, right? :)


>> text_file=open("Hamburg_Dortmund20_00","w")
>> text_file.write("Hamburg-Dortmund")
>> text_file.close()

>Hmmm, that looks suspicious. You just created a text file with
one line.

I thought I should make it as simple as possible when posting here?
If you would have liked me to I can paste all the information I store
in the file, but it would have been a lot of lines then, which would had
been unnecessary?

>> def chair_color_red():
>> global chair1_color
>> chair1_color=("yellow")
>> change_button2_color_red()

>The function says red but the code says 'yellow'????

My bad. It is supposed the be red there.



>> self.chair1.configure(bg="green")
>> os.remove ("Hamburg_Dortmund20_00")

>And now you delete that file you created without having
>done anything with it?

The meaning is that when the button is pressed once,  it changes color and 
creates the file. That means you have
booked the chair. If you click the button once more, the button removes the 
file, and changes color to green
which indicates that you have un booked your chair. I hope you understand 
now why I delete the file :)



(*)Instead of a dictionary we could have used a class
but I think that's a leap too far for you just yet. But
this is a project that would be easier using classes
and objects. An exercise for the future.

I have made simple programs with classes before. I know how to use these
instance variables (correct name in english?) and how to create objects of 
the class,
but nothing more.

>I suspect this is all a bit much in one go, if so, we can
break it down into more manageable chunks.

Yes, it feels like a lot to take in at once, but tomorrow I will try your 
suggestions
for a couple of hours and hopefully get it to work. If I fail at that, 
perhaps we could
"break it down into more manageable chunks".

Thanks for your help once again!


Mic 



More information about the Tutor mailing list