Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from PIL import ImageTk, Image
- from tkinter import messagebox
- from tkcalendar import Calendar
- import connection
- import subprocess
- class LoginForm:
- def __init__(self, window):
- self.window = window
- self.window.geometry('1200x628')
- self.window.resizable(0, 0)
- self.window.state('zoomed')
- # Background image
- self.bg_frame = Image.open('images\\background1.png')
- photo = ImageTk.PhotoImage(self.bg_frame)
- self.bg_panel = Label(self.window, image=photo)
- self.bg_panel.image = photo
- self.bg_panel.pack(fill='both', expand='yes')
- # Login frame
- self.lgn_frame = Frame(self.window, bg='black', width='843', height='777')
- self.lgn_frame.place(x=300, y=25)
- self.txt = 'WELCOME'
- self.heading = Label(self.lgn_frame, text=self.txt, font=('yu gothic ui', 25, 'bold'), bg='black', fg='white')
- self.heading.place(x=80, y=30, width=300, height=30)
- # Left side image
- self.side_image = Image.open('images\\trainnobg.jpg')
- photo = ImageTk.PhotoImage(self.side_image)
- self.side_image_label = Label(self.lgn_frame, image=photo, bg='#040405')
- self.side_image_label.image = photo
- self.side_image_label.place(x=-5, y=-159, width=600, height=900)
- # Sign in image
- self.sign_in_image = Image.open('images\\irctclogo.png')
- photo = ImageTk.PhotoImage(self.sign_in_image)
- self.sign_in_image_label = Label(self.lgn_frame, image=photo, bg='black')
- self.sign_in_image_label.image = photo
- self.sign_in_image_label.place(x=750, y=75)
- # Book Ticket label
- self.sign_in_image_label = Label(self.lgn_frame, text='Book Ticket', bg='#040405', fg='white', font=('yu gothic ui', 13, 'bold'))
- self.sign_in_image_label.place(x=663, y=300)
- # From location
- self.username_label = Label(self.lgn_frame, text='From: ', bg='#040405', font=('yu gothic ui', 13, 'bold'), fg='white')
- self.username_label.place(x=600, y=350)
- self.from_entry = Entry(self.lgn_frame, highlightthickness=0, relief=FLAT, bg='#040405', fg='white', font=('yu gothic ui', 13, 'bold'))
- self.from_entry.place(x=685, y=350, width=270)
- self.username_line = Canvas(self.lgn_frame, width=300, height=2.0, bg='#bdb9b1', highlightthickness=0)
- self.username_line.place(x=600, y=375)
- # To location
- self.username_label = Label(self.lgn_frame, text='To: ', bg='#040405', font=('yu gothic ui', 13, 'bold'), fg='white')
- self.username_label.place(x=600, y=450)
- self.to_entry = Entry(self.lgn_frame, highlightthickness=0, relief=FLAT, bg='#040405', fg='white', font=('yu gothic ui', 13, 'bold'))
- self.to_entry.place(x=685, y=450, width=270)
- self.username_line = Canvas(self.lgn_frame, width=300, height=2.0, bg='#bdb9b1', highlightthickness=0)
- self.username_line.place(x=600, y=475)
- # Seats
- self.username_label = Label(self.lgn_frame, text='Seats: ', bg='#040405', font=('yu gothic ui', 13, 'bold'), fg='white')
- self.username_label.place(x=600, y=520)
- self.seats_entry = Entry(self.lgn_frame, highlightthickness=0, relief=FLAT, bg='#040405', fg='white', font=('yu gothic ui', 13, 'bold'))
- self.seats_entry.place(x=685, y=520, width=270)
- # Scrollbar
- scrollbar_frame = Frame(self.lgn_frame, bg='#040405')
- scrollbar_frame.place(x=600, y=575, height=100)
- scrollbar_canvas = Canvas(scrollbar_frame, bg='#040405', highlightthickness=0)
- scrollbar_canvas.pack(side=LEFT, fill=BOTH, expand=True)
- scrollbar = Scrollbar(scrollbar_frame, orient=VERTICAL, command=scrollbar_canvas.yview)
- scrollbar.pack(side=RIGHT, fill=Y)
- options = ['General', 'Ladies', 'Lower Berth', 'Person with Disability', 'Tatkal', 'Duty Pass']
- self.option_listbox = Listbox(scrollbar_canvas, bg='#040405', fg='white', bd=0, highlightthickness=0, font=('yu gothic ui', 12, 'bold'))
- self.username_line = Canvas(self.lgn_frame, width=300, height=2.0, bg='#bdb9b1', highlightthickness=0)
- self.username_line.place(x=600, y=550)
- for option in options:
- self.option_listbox.insert(END, option)
- self.option_listbox.pack(side=LEFT, fill=BOTH, expand=True)
- self.option_listbox.config(yscrollcommand=scrollbar.set)
- # Label to display selected item
- self.selected_label = Label(self.lgn_frame, text="", bg="#040405", fg="white",
- font=('yu gothic ui', 12, 'bold'))
- self.selected_label.place(x=680, y=520)
- # Bind listbox select event
- self.option_listbox.bind("<<ListboxSelect>>", self.on_select)
- # Date
- self.date_label = Label(self.lgn_frame, text='Date: ', bg='#040405', font=('yu gothic ui', 13, 'bold'), fg='white')
- self.date_label.place(x=315, y=500)
- self.username_line = Canvas(self.lgn_frame, width=250, height=2.0, bg='#bdb9b1', highlightthickness=0)
- self.username_line.place(x=315, y=545)
- self.cal = Calendar(self.lgn_frame, selectmode="day", year=2024, month=2, day=18, background='#040405',
- foreground='white', headersbackground='#040405', headersforeground='white')
- self.cal.place(x=300, y=570, width=270)
- # Button to get selected date
- self.get_date_button = Button(self.lgn_frame, text="Get Date", command=self.get_date, bg='#040405', fg='white',
- font=('yu gothic ui', 13, 'bold'))
- self.get_date_button.place(x=390, y=502, height=25, width=75)
- # Label to display selected date
- self.selected_date_label = Label(self.lgn_frame, text="", bg="#040405", fg="white", font=('yu gothic ui', 12, 'bold'))
- self.selected_date_label.place(x=480, y=500)
- # Search button
- self.search_button = Button(self.lgn_frame, text="Search", bg='red', fg='white', font=('yu gothic ui', 13, 'bold'), command=self.search_trains_wrapper, cursor='hand2')
- self.search_button.place(x=600, y=695, height=30, width=100)
- def execute_signin_script(self):
- subprocess.Popen(['python', 'signin.py'])
- def get_date(self):
- selected_date = self.cal.get_date()
- self.selected_date_label.config(text=selected_date)
- def on_select(self, event):
- selection = event.widget.curselection()
- if selection:
- index = selection[0]
- data = event.widget.get(index)
- self.selected_label.config(text=data)
- def fetch_available_dates(self, ac_tier):
- available_dates = [f"2024-03-{day}" for day in range(20, 31)]
- return available_dates
- def display_available_dates(self, ac_tier):
- available_dates = self.fetch_available_dates(ac_tier)
- dates_window = Toplevel(self.window)
- dates_window.title(f"Available Dates for {ac_tier}")
- dates_window.geometry('1500x400')
- dates_frame = Frame(dates_window, bg='#040405')
- dates_frame.pack(fill='both', expand=True)
- dates_label = Label(dates_frame, text=f"Available Dates for {ac_tier}", bg='#040405', fg='white', font=('yu gothic ui', 16, 'bold'))
- dates_label.pack(pady=10)
- # Create a horizontal scrollbar to display dates
- dates_canvas = Canvas(dates_frame, bg='#040405', highlightthickness=0)
- dates_canvas.pack(side=TOP, fill=BOTH, expand=True)
- scrollbar = Scrollbar(dates_frame, orient=HORIZONTAL, command=dates_canvas.xview)
- scrollbar.pack(side=BOTTOM, fill=X)
- dates_canvas.configure(xscrollcommand=scrollbar.set)
- dates_frame_inner = Frame(dates_canvas, bg='#040405')
- dates_canvas.create_window((0, 0), window=dates_frame_inner, anchor='nw')
- # Add date buttons to the frame
- for i, date in enumerate(available_dates):
- date_button = Button(dates_frame_inner, text=date, bg='red', fg='white', font=('yu gothic ui', 12, 'bold'),
- command=lambda d=date: self.display_available_seats(ac_tier, d))
- date_button.grid(row=0, column=i, padx=5, pady=5)
- # Update scroll region
- dates_frame_inner.update_idletasks()
- dates_canvas.config(scrollregion=dates_canvas.bbox("all"))
- def display_available_seats(self, ac_tier, selected_date):
- available_seats = self.fetch_available_seats(ac_tier, selected_date)
- seats_window = Toplevel(self.window)
- seats_window.title(f"Available Seats for {ac_tier} on {selected_date}")
- seats_window.geometry('500x400')
- seats_frame = Frame(seats_window, bg='#040405')
- seats_frame.pack(fill='both', expand=True)
- seats_label = Label(seats_frame, text=f"Available Seats for {ac_tier} on {selected_date}", bg='#040405',
- fg='white', font=('yu gothic ui', 16, 'bold'))
- seats_label.pack(pady=10)
- if available_seats:
- for i, seat_type in enumerate(available_seats):
- seat_button = Button(seats_frame, text=seat_type, bg='red', fg='white',
- font=('yu gothic ui', 12, 'bold'))
- seat_button.pack(pady=5)
- else:
- no_seats_label = Label(seats_frame, text="No seats available for the selected date.", bg='#040405',
- fg='white', font=('yu gothic ui', 12))
- no_seats_label.pack(pady=10)
- def search_trains_wrapper(self):
- from_location = self.from_entry.get()
- to_location = self.to_entry.get()
- date = self.cal.get_date()
- if not (from_location and to_location and date):
- # If any of the fields are empty, display a message
- messagebox.showerror("Error", "Please fill in all the required fields.")
- return
- # Call search_trains function from connection module
- results = connection.search_trains(from_location, to_location, date)
- # Display search results
- if results:
- self.display_search_results(results)
- else:
- messagebox.showinfo("No Results", "No trains found for the given criteria.")
- def display_search_results(self, results):
- # Function to display search results
- # You can update this method to display the results in a separate window or in the current window
- results_window = Toplevel(self.window)
- results_window.title("Search Results")
- results_window.geometry('800x600')
- # Create a frame to hold the results
- results_frame = Frame(results_window, bg='#040405')
- results_frame.pack(fill='both', expand=True)
- # Add a label for the heading
- heading_label = Label(results_frame, text="Search Results", bg='#040405', fg='white',
- font=('yu gothic ui', 18, 'bold'))
- heading_label.pack(pady=10)
- if results:
- # Iterate over the results and display them
- for result in results:
- train_frame = Frame(results_window, bg='#040405')
- train_frame.pack(fill='both', expand=True)
- result_label = Label(results_frame, text=result, bg='#040405', fg='white', font=('yu gothic ui', 12))
- result_label.pack(pady=15, padx=10)
- else:
- # If no results found, display a message
- no_results_label = Label(results_frame, text="No trains found for the given criteria.", bg='#040405',
- fg='white', font=('yu gothic ui', 12))
- no_results_label.pack(pady=10)
- close_button = Button(results_frame, text="Close", command=results_window.destroy, bg='red', fg='white',font=('yu gothic ui', 12, 'bold'),cursor='hand2')
- close_button.place(x=350, y=380)
- ACTier1A = Button(results_frame, text="AC Tier 1", bg='red', fg='white', font=('yu gothic ui', 12, 'bold'), command=lambda: self.display_available_dates("AC Tier 1"), cursor='hand2')
- ACTier1A.place(x=200, y=110)
- ACTier2A = Button(results_frame, text="AC Tier 2", bg='red', fg='white', font=('yu gothic ui', 12, 'bold'), command=lambda: self.display_available_dates("AC Tier 2"), cursor='hand2')
- ACTier2A.place(x=350, y=110)
- ACTier1A = Button(results_frame, text="AC Tier 1", bg='red', fg='white', font=('yu gothic ui', 12, 'bold'), command=lambda: self.display_available_dates("AC Tier 1"), cursor='hand2')
- ACTier1A.place(x=200, y=190)
- ACTier2A = Button(results_frame, text="AC Tier 2", bg='red', fg='white', font=('yu gothic ui', 12, 'bold'), command=lambda: self.display_available_dates("AC Tier 2"), cursor='hand2')
- ACTier2A.place(x=350, y=190)
- def fetch_available_dates(self, ac_tier):
- available_dates = [f"2024-04-{day}" for day in range(1, 31)] # Mocked available dates
- return available_dates
- def fetch_available_seats(self, ac_tier, selected_date):
- # Mocking the seat types based on selected_date and AC tier
- seat_types = {
- "2024-04-1": ["A-12", "B-32", "B-05", "C-34", "C-42"],
- "2024-04-2": ["A-21", "B-42", "B-45", "C-44", "C-45"],
- "2024-04-3": ["A-21", "B-42", "B-65", "C-44", "C-45"],
- "2024-04-4": ["A-21", "B-42", "B-25", "C-44", "C-45"],
- "2024-04-5": ["A-21", "B-42", "B-15", "C-44", "C-45"],
- "2024-04-6": ["A-21", "B-42", "B-05", "C-44", "C-45"],
- "2024-04-7": ["A-21", "B-42", "B-35", "C-44", "C-45", "A-32",],
- "2024-04-8": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-9": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-10": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-11": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-12": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-13": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-14": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-15": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-16": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-17": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-18": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-19": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-20": ["A-21", "B-42", "B-35", "C-44", "C-45"],
- "2024-04-21": ["A-26", "A-27", "B-28", "B-29"],
- "2024-04-22": ["A-30", "A-31", "B-32", "D-11"],
- "2024-04-23": ["A-33", "A-34", "B-35", "C-36", "C-37", "D-12"],
- "2024-04-24": ["A-38", "A-39", "B-40", "C-42", "C-43", "C-44", "D-22"],
- "2024-04-25": ["A-40", "A-41", "B-42", "C-42", "C-46", "C-44", "D-11"],
- "2024-04-26": ["B-42", "B-43", "B-44", "C-11"],
- "2024-04-27": ["A-11", "B-42", "C-42", "B-19"],
- "2024-04-28": ["A-21", "B-42", "C-42", "B-20", "C-20", "D-12"],
- "2024-04-29": ["A-32, B-26", "C-38", "B-7"],
- "2024-04-30": ["A-33", "C-39", "B-40", "C-45,A-41"],
- "2024-04-31": ["A-12", "B-42", "C-42", "B-34", "C-44", "C-44", "D-21"]
- }
- return seat_types.get(selected_date, [])
- def seat_type_selected(self, seat_type):
- # Function to display a confirmation message when a seat type button is clicked
- confirmation_window = Toplevel(self.window)
- confirmation_window.title("Ticket Booking Confirmation")
- confirmation_window.geometry('400x200')
- confirmation_frame = Frame(confirmation_window, bg='#040405')
- confirmation_frame.pack(fill='both', expand=True)
- confirmation_label = Label(confirmation_frame, text=f"Your ticket for {seat_type} is booked!", bg='#040405',
- fg='white', font=('yu gothic ui', 16, 'bold'))
- confirmation_label.pack(pady=50)
- close_button = Button(confirmation_frame, text="Close", command=confirmation_window.destroy, bg='red',
- fg='white',
- font=('yu gothic ui', 12, 'bold'), cursor='hand2')
- close_button.pack()
- def display_available_dates(self, ac_tier):
- available_dates = self.fetch_available_dates(ac_tier)
- dates_window = Toplevel(self.window)
- dates_window.title(f"Available Dates for {ac_tier}")
- dates_window.geometry('1500x400')
- dates_frame = Frame(dates_window, bg='#040405')
- dates_frame.pack(fill='both', expand=True)
- dates_label = Label(dates_frame, text=f"Available Dates for {ac_tier}", bg='#040405', fg='white',
- font=('yu gothic ui', 16, 'bold'))
- dates_label.pack(pady=10)
- # Create a horizontal scrollbar to display dates
- dates_canvas = Canvas(dates_frame, bg='#040405', highlightthickness=0)
- dates_canvas.pack(side=TOP, fill=BOTH, expand=True)
- scrollbar = Scrollbar(dates_frame, orient=HORIZONTAL, command=dates_canvas.xview)
- scrollbar.pack(side=BOTTOM, fill=X)
- dates_canvas.configure(xscrollcommand=scrollbar.set)
- dates_frame_inner = Frame(dates_canvas, bg='#040405')
- dates_canvas.create_window((0, 0), window=dates_frame_inner, anchor='nw')
- # Add date buttons to the frame
- for i, date in enumerate(available_dates):
- date_button = Button(dates_frame_inner, text=date, bg='red', fg='white', font=('yu gothic ui', 12, 'bold'),
- command=lambda d=date: self.display_available_seats(ac_tier, d))
- date_button.grid(row=0, column=i, padx=5, pady=5)
- # Update scroll region
- dates_frame_inner.update_idletasks()
- dates_canvas.config(scrollregion=dates_canvas.bbox("all"))
- def display_available_seats(self, ac_tier, selected_date):
- available_seats = self.fetch_available_seats(ac_tier, selected_date)
- seats_window = Toplevel(self.window)
- seats_window.title(f"Available Seats for {ac_tier} on {selected_date}")
- seats_window.geometry('500x400')
- seats_frame = Frame(seats_window, bg='#040405')
- seats_frame.pack(fill='both', expand=True)
- seats_label = Label(seats_frame, text=f"Available Seats for {ac_tier} ", bg='#040405',
- fg='white', font=('yu gothic ui', 16, 'bold'))
- seats_label.pack(pady=10)
- # Inside display_available_seats method
- if available_seats:
- for i, seat_type in enumerate(available_seats):
- seat_button = Button(seats_frame, text=seat_type, bg='red', fg='white',
- font=('yu gothic ui', 12, 'bold'))
- seat_button.config(command=lambda st=seat_type, : self.seat_type_selected(st)) # Bind seat type to method
- seat_button.pack(pady=5)
- else:
- no_seats_label = Label(seats_frame, text="No seats available for the selected date.", bg='#040405',
- fg='white', font=('yu gothic ui', 12))
- no_seats_label.pack(pady=10)
- def page():
- window = Tk()
- LoginForm(window)
- window.mainloop()
- if __name__ == '__main__':
- page()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement