[Tutor] Creating arbitrary numbers of destinations. (GUI)

Mic o0MB0o at hotmail.se
Wed Dec 7 16:16:01 CET 2011


>Thanks, although you actually missed a step somewhere - the bit where
>the user selects how many chairs... But ignoring that...
>Where do we select how many destinations you want?
>If we stick to 3 for now:

Actually, the user never selects how many destinations that he wants. It is 
in the code you should be able to change it.
As seen in my code, you change the amount of chairs by changing the value of 
the variable NUMBERSOFCHAIRS.
I want to be able to create as many destinations as I would like in a 
smiliar way, provided there isn't a better way to go.
Was this understandable?

>> 1.User starts program.
>> 2.User choose destination1.
>> 3. window with chairs appear.
>> ....  selects chairs
>> 7. He can choose another destination, which repats step 2-6.

>OK, So the real question is how to create three buttons each of which
>can launch a window to select chairs. But this is just the same as your
>chairs window. You just create buttons and link them to a function which
>opens the chair window.

>And if you do want more buttons you just do exactly what you did with
>the chairs...

Okay, I will try that!

> I really hope I made my intentions clearer now. Tell me if it is still
> unclear or confusing!

>Clearer, although there are still some bits missing - like how the user
>selects the number of destinations/chairs.

As stated above, the users aren't allowed to change the number of 
destinations and chairs, it is supposed to be changed in the code, by 
changing the value of
a variable :)


>> from tkinter import*
>> import tkinter as tk

>You only need one of these two lines, the second is
>probably best.

Okay, thanks!

> >import os
> >NUMBEROFCHAIRS=32
>
> >class ChooseDestinationWindow(Frame):
> >def __init__(self,master):
> >super(ChooseDestinationWindow,self).__init__(master)
>> self.grid()
>> self.create_different_destinations()
>
> def create_different_destinations(self):
>> self.destination1=Button(self,
>>text="Destination1",command=self.Destination1_function)
>> self.destination1.grid()
>
>> self.destination2=Button(self, text="Destination2")
>> self.destination2.grid()
>
> >self.destination3=Button(self,text="Destination3")
>> self.destination3.grid()


>OK, that should work except you haven't set the command value to the
>function that creates the seat booking window. You probabvly also want
>to set the filename here too

Hmm, yes but I don't want to write two lines of code for each chair I 
create, I want them in
a for loop, if that is convienient?




>> def Destination1_function(self):
>> class Seats_Destination1(tk.Button):

>I see you are still defining your classes inside yoyur functions. It
>really is more normal (and useful) to define them all at the top level.
>It also makes your functions easier to read!

Really? I actually thinks it is easier to read the code using inner classes, 
but
thats just me probably!




> class Destination1_Chairs(Frame):

This is the thing you want to call from your destination buttons. So
create a method in the top level window that creates one of these objects.

>> root=Tk()
>> root.title("Booking Window")
>> app=Destination1_Chairs(root)
>>root.mainloop()
>
>
> >root=Tk()
> >root.title("Choose your destination")
> >root.geometry("900x200")
> >app=ChooseDestinationWindow(root)
> >root.mainloop()

>And you still have multiple root objects and multiple
>mainloops. That's bad practice and it will bite you
>eventually.

Yes, it actually bit me last week :) I will work on that when I have solved 
this problem with the destinations:)
Thanks for your suggestions!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



------------------------------

_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 94, Issue 20
************************************* 



More information about the Tutor mailing list