Hi again :)
First of all, I thought the topic name was correct. Arbitrary means as many as one would like or a realistic number right?

I am back with one of my TKinter programs and with new questions:

I have written a program where you can book train tickets. At first , there were only a fixed number of seats availible to book, but I have now manged to create as many seats as I would like. That's nice. However, this was only for one destination. I want to be able to have as many destinations as I want.
The numbers of seats should be the same for every destination.

I sat the entire evening and afternoon trying to get it to work yesterday, but I have no idea on how to accomplish this. I tried using for i in range() and while loops, without success sadly. Here is the code so far. I translated all variable name and function names to English, so sorry if I missed something.


from tkinter import*
import tkinter as tk
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()

   def Destination1_function(self):
                class Seats_Destination1(tk.Button):
                     def __init__(self,master,index):
                          text=str(index+1)
                          self.OCCUPIED="red"
                          self.FREE="green"
                          super(Seats_Destination1, self).__init__(master,
                                         text=text, bg=self.FREE,
                                         command=self.PressedChair)
self.filename2 = "Destination1{}.txt".format(index+1)
                          self.occupied = False

                          if os.path.exists(self.filename2):
                               self["bg"]=self.OCCUPIED
                               self.OCCUPIED=True


                     def PressedChair(self):
                          self.occupied = not self.occupied
                          if self.occupied:
                               self["bg"] = self.OCCUPIED
                               text_file=open(self.filename2,"w")
                               text_file.write(self.filename2)
                               text_file.close()
                          else:
                               self["bg"] = self.FREE
                               try:
                                   os.remove(self.filename2)
                               except:
                                   pass



                class Destination1_Chairs(Frame):
                     def __init__(self,master):
                          super(Destination1_Chairs,self).__init__(master)
                          self.grid()
                          self.Create_Chairs()

                      Satt till 32.
                     def Create_Chairs(self):
                          for index in range(NUMBEROFCHAIRS):
                               button = Seats_Destination1(self, index)
                               row, column = divmod(index, 4)
                               button.grid(row=row, column=column)
                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()




Thanks for your time and help!


Mic




_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to