Booked Flight
self.root = tk.Toplevel()
# root = tk.Tk()
self.root.title("Flight Booking")
color = "#FFFFFF"
self.root.configure(bg="#585858")
self.root.resizable(width=0, height=0)
win_width = 1400
print(1280 * 56.25 / 100)
win_height = int(1280 * 56.25 / 100)
self.root.geometry(str(win_width) + "x" + str(win_height))
Util.center(self.root)
# Get screen size
screen_width = self.root.winfo_screenwidth()
screen_height = self.root.winfo_screenheight()
Util.set_font_size(screen_width, screen_height, win_width, win_height)
self.width = win_width * 96 / 100
self.height = win_height * 94 / 100
cornerradius = 40
padding = 0
self.color = "#FFFFFF"
After creation of window, we will add a canvas background.
bg_canvas = RoundBackgroundFrame(self.root, self.width, self.height, padding, cornerradius, self.color,"#585858")
bg_canvas.place(width=self.width, height=self.height, x=win_width / 2 - self.width / 2, y=win_height / 2 - self.height / 2)
class RoundBackgroundFrame(tk.Canvas):
def __init__(self, parent, width, height, padding, cornerradius, color, bg):
tk.Canvas.__init__(self, parent, borderwidth=0, relief="flat", highlightthickness=0, bg=bg)
original = Image.open("images/corner.png")
resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
self.image_r_t = ImageTk.PhotoImage(resized)
original = original.rotate(90, expand=0)
resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
self.image_l_t = ImageTk.PhotoImage(resized)
original = original.rotate(90, expand=0)
resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
self.image_l_b = ImageTk.PhotoImage(resized)
original = original.rotate(90, expand=0)
resized = original.resize((int(40), int(40)), Image.ANTIALIAS)
self.image_r_b = ImageTk.PhotoImage(resized)
self.shape(width, height, padding, cornerradius, color)
(x0, y0, x1, y1) = self.bbox("all")
width = (x1 - x0)
height = (y1 - y0)
self.configure(width=width, height=height)
def shape(self, width, height, padding, cornerradius, color):
self.create_polygon((padding, height - cornerradius - padding, padding, cornerradius + padding,
padding + cornerradius, padding, width - padding - cornerradius, padding,
width - padding, cornerradius + padding, width - padding,
height - cornerradius - padding, width - padding - cornerradius, height - padding,
padding + cornerradius, height - padding), fill=color, outline=color)
self.create_image(width - self.image_r_t.width(), 0, image=self.image_r_t, anchor=NW)
self.create_image(0, 0, image=self.image_l_t, anchor=NW)
self.create_image(0, height - self.image_l_b.width(), image=self.image_l_b, anchor=NW)
self.create_image(width - self.image_r_b.width(), height - self.image_r_b.width(), image=self.image_r_b,anchor=NW)
self.width = self.width * 98 / 100
self.height = self.height * 96 / 100
self.base_frame = Frame(root, width=self.width, height=self.height, bg=self.color)
bg_canvas.create_window(self.width / 100, self.height * 2 / 100, anchor=NW, window=self.base_frame)
# Add Heading Name
add_heading_label(self.base_frame, self.color, AppConstant.FONT_SIZE, self.height, self.width)
def add_heading_label(base_frame, color, font_size, height, width):
label_heading = Label(base_frame, text="Booked Flight", anchor=CENTER, bg=color,
font=("Lucida Grande", font_size + 4))
label_heading.place(width=width * 90 / 100, height=height * 5 / 100, x=width * 5 / 100, y=height * 0.3 / 100)
# Add line
add_line_border(self.base_frame, self.color, self.height, self.width)
def add_line_border(base_frame, color, height, width):
line_canvas = Canvas(base_frame, bg=color, borderwidth=0, relief="flat", highlightthickness=0)
line_canvas.place(width=width - 4, height=5, x=2, y=height * 10 / 100)
line_canvas.create_line(0, 0, width, 0, fill="#787878")
button_font = add_action_frame(self.base_frame, self.color, self.height, self.width)
def add_action_frame(base_frame, color, height, width):
afw = width * 0.32
afh = height * 0.90
button_font = ("Lucida Grande", AppConstant.FONT_SIZE - 6)
label_frame_action = LabelFrame(base_frame, text="Actions", font=button_font, pady=afw * 2 / 100,
padx=afw * 2 / 100, bg=color)
label_frame_action.place(width=afw, height=afh, x=width * 0.68, y=height * 0.09)
return button_font
add_search_frame(self.base_frame, ("Lucida Grande", AppConstant.FONT_SIZE - 6), self.color, self.height, self.width)
def add_search_frame(base_frame, button_font, color, height, width):
sfw = width * 0.98
sfh = height * 0.87
label_frame_search = LabelFrame(base_frame, text="Search", font=button_font, pady=sfw * 2 / 100,
padx=sfw * 2 / 100, bg=color)
So we are done with all frame and background UI. Now we will add search box.
self.ce_booking_var = CustomEntry(self.base_frame, 300, 55, 10, 2, self.color, "Search Booked Ticket",
"images/ic_search.png")
self.ce_booking_var.place(x=91, y=self.height * 0.20)
self.booking_var = tk.StringVar
self.ce_booking_var.entry.bind('', self.search_booking)
def search_booking(self, *arg):
# self.hide_edit_button()
if self.ce_booking_var.entry.get() != "":
self.tree.delete(*self.tree.get_children())
conn = Util.connect_db()
cursor = conn.cursor()
cursor.execute("SELECT * FROM `booking` WHERE `passenger_id` LIKE ? OR `booking_id` LIKE ? OR `flight_no` LIKE ?",
('%' + str(self.ce_booking_var.entry.get()) + '%',
'%' + str(self.ce_booking_var.entry.get()) + '%', '%' + str(self.ce_booking_var.entry.get()) + '%'))
fetch = cursor.fetchall()
count = 0
booked_ticket_data_list = []
for data in fetch:
cursor.execute(
'SELECT flight_name, route, departure_timing, arrival_timing FROM flight_detail where flight_no IS ?',
(data[1],))
sql_output_two = cursor.fetchall()
print(sql_output_two)
cursor.execute(
'SELECT passenger_name, contact_number FROM passenger_detail where passenger_id IS ?',
(data[2],))
sql_output_three = cursor.fetchall()
print(sql_output_three)
flight_tuple = (data[0],)
passenger_tuple = (data[3],)
# booked_ticket_data_list.append((flight_tuple))
self.tree.insert('', 'end',
values=flight_tuple + sql_output_two[0] + sql_output_three[0] + passenger_tuple)
print(flight_tuple + sql_output_two[0] + sql_output_three[0] + passenger_tuple)
count += 1
# for data in fetch:
# if count % 2 == 0:
# self.tree.insert('', 'end', values=data, tags=('even',))
# else:
# self.tree.insert('', 'end', values=data, tags=('odd',))
# count = count + 1
# for data in fetch:
# self.tree.insert('', 'end', values=data)
cursor.close()
conn.close()
else:
self.reset_book()
def reset_book(self):
self.tree.delete(*self.tree.get_children())
self.update_table_data()
class Util:
@staticmethod
def connect_db():
db = None
try:
db = sql.connect("flight.db")
return db
except sql.Error as error:
print("Failed to insert data into sqlite table", error)
Here is our class CustomEntrySimple:
class CustomEntry(tk.Canvas):
def __init__(self, parent, width, height, cornerradius, padding, color, text, icon_path):
tk.Canvas.__init__(self, parent, borderwidth=0, relief="flat", highlightthickness=0, bg=color)
self.width = width
self.height = height
self.cornerradius = cornerradius
self.padding = padding
self.color = color
original = Image.open(icon_path)
resized = original.resize((int(height * 35 / 100), int(height * 35 / 100)), Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(resized) # Keep a reference, prevent GC
# self.color_text = "white"
self.create_text(6, 7, anchor=W, font=font.Font(family="Lucida Grande", size=12, weight='bold'),
text=text, fill="#000000")
self.create_image(10, height / 2 - self.image.width() / 2, image=self.image, anchor=NW)
self.create_line(5, height - 8, width - 5, height - 8, fill="#808080")
frame = Frame(parent,width=width * 86 / 100, height=height * 50 / 100, bg=color)
# frame.place(x=0, y=0, width=100, height=50)
self.entry = Entry(frame, bg=color, bd=0, highlightthickness=0,
font=font.Font(family="Lucida Grande", size=13, weight='normal'))
self.entry.place(relwidth=1, relheight=1, x=0, y=0)
self.create_window(width - width * 86 / 100 - 5, height / 2 - (height * 50 / 100) / 2, anchor=NW, window=frame)
self.update()
(x0, y0, x1, y1) = self.bbox("all")
width = (x1 - x0)
height = (y1 - y0)
self.configure(width=width, height=height)
style = ttk.Style()
# style.element_create("Custom.Treeheading.border", "from", "default")
style.layout("Custom.Treeview.Heading", [
("Custom.Treeheading.cell", {'sticky': 'nswe'}),
("Custom.Treeheading.border", {'sticky': 'nswe', 'children': [
("Custom.Treeheading.padding", {'sticky': 'nswe', 'children': [
("Custom.Treeheading.image", {'side': 'right', 'sticky': ''}),
("Custom.Treeheading.text", {'sticky': 'we'})
]})
]}),
])
# style.configure("Custom.Treeview.Heading", background="blue", foreground="red", relief="flat")
style.map("Custom.Treeview.Heading", relief=[('active', 'groove'), ('pressed', 'sunken')])
style.configure("Custom.Treeview", highlightthickness=0, bd=0, font=('Calibri', 11), rowheight=30)
self.table_heading()
self.tree = ttk.Treeview(self.base_frame, height=13, show='tree', style="Custom.Treeview")
self.tree.tag_configure('odd', background='#fcd9e1', foreground="#000000", )
self.tree.tag_configure('even', background='#FFFFFF', foreground="#000000", )
self.tree.place(x=25, y=230)
self.tree["columns"] = "1", "2", "3", "4", "5", "6", "7", "8"
self.tree.column("#0", width=0)
self.tree.column("#1", width=120)
self.tree.column("#2", width=150)
self.tree.column("#3", width=190)
self.tree.column("#4", width=120)
self.tree.column("#5", width=120)
self.tree.column("#6", width=180)
self.tree.column("#7", width=120)
self.tree.column("#8", width=140)
# count = 0
# for data in self.sql_output:
# if count % 2 == 0:
# self.tree.insert('', 'end', values=data, tags=('even',))
# else:
# self.tree.insert('', 'end', values=data, tags=('odd',))
# count = count + 1
self.get_table_data()
vsb = ttk.Scrollbar(self.base_frame, orient="vertical", command=self.tree.yview)
vsb.place(x=self.width - 40, y=230, height=395)
self.tree.configure(yscrollcommand=vsb.set)
self.tree.column("#1", anchor=tk.CENTER)
self.tree.column("#2", anchor=tk.CENTER)
self.tree.column("#3", anchor=tk.CENTER)
self.tree.column("#4", anchor=tk.CENTER)
self.tree.column("#5", anchor=tk.CENTER)
self.tree.column("#6", anchor=tk.CENTER)
self.tree.column("#7", anchor=tk.CENTER)
self.tree.column("#8", anchor=tk.CENTER)
root.attributes('-alpha', 0.0)
Util.center(root)
root.attributes('-alpha', 1.0)
def get_table_data(self):
conn = Util.connect_db()
cursor = conn.cursor()
cursor.execute('SELECT * FROM booking')
sql_output = cursor.fetchall()
print(sql_output)
count = 0
booked_ticket_data_list = []
booked_ticket_data_list2 = []
for data in sql_output:
cursor.execute(
'SELECT flight_name, route, departure_timing, arrival_timing FROM flight_detail where flight_no IS ?', (data[1],))
sql_output_two = cursor.fetchall()
print(sql_output_two)
cursor.execute(
'SELECT passenger_name, contact_number FROM passenger_detail where passenger_id IS ?',
(data[2],))
sql_output_three = cursor.fetchall()
print(sql_output_three)
flight_tuple = (data[0],)
passenger_tuple = (data[3],)
# booked_ticket_data_list.append((flight_tuple))
self.tree.insert('', 'end', values=flight_tuple + sql_output_two[0] + sql_output_three[0]+passenger_tuple)
print(flight_tuple + sql_output_two[0] + sql_output_three[0]+ passenger_tuple)
count += 1
Update the table UI for every insertation and deletation should be catch
def update_table_data(self):
conn = Util.connect_db()
cursor = conn.cursor()
cursor.execute('SELECT * FROM booking')
sql_output = cursor.fetchall()
print(sql_output)
count = 0
booked_ticket_data_list = []
booked_ticket_data_list2 = []
for data in sql_output:
cursor.execute(
'SELECT flight_name, route, departure_timing, arrival_timing FROM flight_detail where flight_no IS ?',
(data[1],))
sql_output_two = cursor.fetchall()
print(sql_output_two)
cursor.execute(
'SELECT passenger_name, contact_number FROM passenger_detail where passenger_id IS ?',
(data[2],))
sql_output_three = cursor.fetchall()
print(sql_output_three)
flight_tuple = (data[0],)
passenger_tuple = (data[3],)
# booked_ticket_data_list.append((flight_tuple))
self.tree.insert('', 'end', values=flight_tuple + sql_output_two[0] + sql_output_three[0] + passenger_tuple)
print(flight_tuple + sql_output_two[0] + sql_output_three[0] + passenger_tuple)
count += 1
def add_calender(self):
today_date = int(datetime.datetime.today().strftime('%d'))
today_month = int(datetime.datetime.today().strftime('%m'))
today_year = int(datetime.datetime.today().strftime('%Y'))
# print(today_year+today_month+today_date)
self.cal = Calendar(self.base_frame, selectmode='day',
year=today_year, month=today_month,
day=today_date)
self.cal.place(x=self.width * 69 / 100, y=self.height * 0.74, width=220, height=150)
self.add_calender_button()
Add passenger click it will redirect to add passenger page
add_passenger_detail_frame(self.base_frame, self.color, self.height, self.width)
def add_passenger_detail_frame(base_frame, color, height, width):
afw = width * 0.30
afh = height * 0.23
button_font = ("Lucida Grande", AppConstant.FONT_SIZE - 6)
label_frame_detail = LabelFrame(base_frame, text="Passenger Details", font=button_font, pady=afw * 2 / 100,
padx=afw * 2 / 100, bg=color)
label_frame_detail.place(width=afw, height=afh, x=width * 0.69, y=height * 0.48)
return button_font
#get selected Pasenger
self.selected_passenger_table_detail()
def selected_passenger_table_detail(self):
heading_y = 150
heading_y = 338
bg_color = "#f52f59"
text_color = "#ffffff"
canvas = Canvas(self.base_frame, width=350, height=30)
canvas.create_rectangle(0, 0, 350, 30, fill=bg_color)
canvas.place(x=self.width / 2 + 270, y=heading_y - 3)
book_id_label = ttk.Label(self.base_frame, text="Passenger Detail",
font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
foreground=text_color)
book_id_label.place(x=self.width / 2 + 271, y=heading_y, width=349)
book_id_label.configure(anchor="center")
text_color = "#000000"
bg_color = "#FFFFFF"
self.passenger_name = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
self.passenger_name.place(x=self.width / 2 + 410, y=heading_y + 40, width=200)
self.passenger_name.configure(anchor="center")
self.passenger_contact = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
self.passenger_contact.place(x=self.width / 2 + 430, y=heading_y + 70, width=200)
self.passenger_contact.configure(anchor="center")
self.selected_date = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
self.selected_date.place(x=self.width / 2 + 390, y=heading_y + 100, width=200)
self.selected_date.configure(anchor="center")
# constant labels
name_label = ttk.Label(self.base_frame, text="Passenger Name -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
name_label.place(x=self.width / 2 + 270, y=heading_y + 40, width=155)
# name_label.configure(anchor="center")
contact_label = ttk.Label(self.base_frame, text="Passenger Contact -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
contact_label.place(x=self.width / 2 + 270, y=heading_y + 70, width=155)
# contact_label.configure(anchor="")
date_label = ttk.Label(self.base_frame, text="Selected Date -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
date_label.place(x=self.width / 2 + 270, y=heading_y + 100, width=120)
date_label.configure(anchor="center")
Now i will add the Treeview For search passenger
# ============ passenger Table Data ===============
self.passenger_tree_view = ttk.Treeview(self.base_frame, height=5, columns=("c1", "c2", "c3", "c4"),
show='tree', style="Custom.Treeview")
self.passenger_tree_view.tag_configure('odd', background='#DFEBF6', foreground="#000000", )
self.passenger_tree_view.tag_configure('even', background='#FFFFFF', foreground="#000000", )
self.passenger_tree_view.place(x=20, y=self.height * 0.64)
self.passenger_tree_view.bind('<>')
self.passenger_tree_view.column("#0", width=0)
self.passenger_tree_view.column("#1", width=180, anchor=tk.CENTER)
self.passenger_tree_view.column("#2", width=210, anchor=tk.CENTER)
self.passenger_tree_view.column("#3", width=210, anchor=tk.CENTER)
self.passenger_tree_view.column("#4", width=240, anchor=tk.CENTER)
# self.passenger_tree_view.column("#5", width=150, anchor=tk.CENTER)
# self.passenger_tree_view.column("#6", width=100, anchor=tk.CENTER)
self.passenger_tree_view.bind('<>', self.on_select_book_tree)
self.passenger_table_heading()
vsby1 = ttk.Scrollbar(self.base_frame, orient="vertical", command=self.passenger_tree_view.yview)
vsby1.place(x=self.width / 2 + 202, y=self.height * 0.64, height=153)
self.passenger_tree_view.configure(yscrollcommand=vsby1.set)
def passenger_table_heading(self):
win_height = int(1280 * 65 / 100)
heading_y = win_height * 47 / 100
text_color = "white"
bg_color = "#f52f59"
canvas = Canvas(self.base_frame, width=840, height=30)
canvas.create_rectangle(0, 0, 840, 30, fill=bg_color)
canvas.place(x=20, y=heading_y - 3)
book_id_label = Label(self.base_frame, text="Passenger Id",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'bold'), background=bg_color,
foreground=text_color)
book_id_label.place(x=45, y=heading_y, width=180)
book_id_label.configure(anchor="center")
book_name_label = Label(self.base_frame, text="Passenger Name",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'bold'), background=bg_color,
foreground=text_color)
book_name_label.place(x=225, y=heading_y, width=210)
book_name_label.configure(anchor="center")
book_authorname_label = Label(self.base_frame, text="Contact Number",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'bold'), background=bg_color,
foreground=text_color)
book_authorname_label.place(x=442, y=heading_y, width=190)
book_authorname_label.configure(anchor="center")
book_price = Label(self.base_frame, text="Email Id",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'bold'), background=bg_color,
foreground=text_color)
book_price.place(x=662, y=heading_y, width=180)
book_price.configure(anchor="center")
#add passenger Button
self.add_passenger_button()
def add_passenger_button(self):
self.add_passenger_button1 = RoundedButton(self.base_frame, 200, 130 / 2.56, self.color, "images/button3.png", "Add Passenger",font=("Lucida Grande", AppConstant.FONT_SIZE - 2),command=lambda: self.add_passenger_click())
self.add_passenger_button1.place(x=600, y=585)
# Get Data from table
self.get_passenger_data()
Now we will find the Passenger data from db, lets configure it.
def get_passenger_data(self):
self.passenger_tree_view.delete(*self.passenger_tree_view.get_children())
db = Util.connect_db()
cursor = db.cursor()
cursor.execute('SELECT * FROM passenger_detail')
sql_output = cursor.fetchall()
count = 0
for data in sql_output:
if count % 2 == 0:
self.passenger_tree_view.insert('', 'end', values=data, tags=('even',))
else:
self.passenger_tree_view.insert('', 'end', values=data, tags=('odd',))
count = count + 1
now we will add the functionality for add get selected flight.
def on_select(self, *arg):
current_item = self.flight_tree.focus()
print(self.flight_tree.item(current_item)["values"][0])
value = self.flight_tree.item(current_item)["values"][1]
self.flight_name.configure(text=self.flight_tree.item(current_item)["values"][1])
self.flight_route.configure(text=self.flight_tree.item(current_item)["values"][2])
self.flight_dep.configure(text=self.flight_tree.item(current_item)["values"][3])
self.flight_ara.configure(text=self.flight_tree.item(current_item)["values"][4])
self.flight_fare.configure(text=self.flight_tree.item(current_item)["values"][5])
# self.flight_available.configure(text=self.flight_tree.item(current_item)["values"][6])
# self.openBookList(self.flight_tree.item(current_item)["values"][0])
def on_selected_passenger(self, *arg):
current_item = self.passenger_tree_view.focus()
print(self.passenger_tree_view.item(current_item)["values"][0])
# self.passenger_id.configure(text=self.passenger_tree_view.item(current_item)["values"][0])
self.passenger_name.configure(text=self.passenger_tree_view.item(current_item)["values"][1])
self.passenger_contact.configure(text=self.passenger_tree_view.item(current_item)["values"][2])
# self.passenger_emailid.configure(text=self.passenger_tree_view.item(current_item)["values"][3])
now we will implemented click functionality for add passenger.
def add_passenger_click(self):
self.root.withdraw()
AddPassenger(self.root, self)
# it will redirect Add passenger page
print("Value")
def selected_flight_table_detail(self):
heading_y = 150
heading_y = 100
bg_color = "#f52f59"
text_color = "#ffffff"
canvas = Canvas(self.base_frame, width=350, height=30)
canvas.create_rectangle(0, 0, 350, 30, fill=bg_color)
canvas.place(x=self.width / 2 + 270, y=heading_y - 3)
book_id_label = ttk.Label(self.base_frame, text="Flight Detail",
font=('Calibri', AppConstant.FONT_SIZE - 3, 'bold'), background=bg_color,
foreground=text_color)
book_id_label.place(x=self.width / 2 + 271, y=heading_y, width=349)
book_id_label.configure(anchor="center")
text_color = "#000000"
bg_color = "#FFFFFF"
self.flight_name = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'normal'), background=bg_color
, foreground=text_color)
self.flight_name.place(x=self.width / 2 + 390, y=heading_y + 40, width=230)
self.flight_name.configure(anchor="center")
self.flight_route = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'normal'), background=bg_color
, foreground=text_color)
self.flight_route.place(x=self.width / 2 + 390, y=heading_y + 70, width=230)
self.flight_route.configure(anchor="center")
self.flight_dep = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'normal'), background=bg_color
, foreground=text_color)
self.flight_dep.place(x=self.width / 2 + 390, y=heading_y + 100, width=230)
self.flight_dep.configure(anchor="center")
self.flight_ara = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'normal'), background=bg_color
, foreground=text_color)
self.flight_ara.place(x=self.width / 2 + 390, y=heading_y + 130, width=230)
self.flight_ara.configure(anchor="center")
self.flight_fare = ttk.Label(self.base_frame, text="",
font=('Calibri', AppConstant.FONT_SIZE - 4, 'normal'), background=bg_color
, foreground=text_color)
self.flight_fare.place(x=self.width / 2 + 390, y=heading_y + 160, width=230)
self.flight_fare.configure(anchor="center")
# self.flight_available = ttk.Label(self.base_frame, text="",
# font=('Calibri', AppConstant.FONT_SIZE - 4, 'normal'), background=bg_color
# , foreground=text_color)
# self.flight_available.place(x=self.width / 2 + 345, y=heading_y + 190, width=250)
# self.flight_available.configure(anchor="center")
# constant labels
name_label = ttk.Label(self.base_frame, text="Flight Name -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
name_label.place(x=self.width / 2 + 270, y=heading_y + 40, width=120)
name_label.configure(anchor="center")
route_label = ttk.Label(self.base_frame, text="Flight Route -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
route_label.place(x=self.width / 2 + 270, y=heading_y + 70, width=120)
route_label.configure(anchor="center")
dep_label = ttk.Label(self.base_frame, text="Departure Time -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
dep_label.place(x=self.width / 2 + 270, y=heading_y + 100, width=120)
dep_label.configure(anchor="center")
ara_label = ttk.Label(self.base_frame, text="Arrival Time -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
ara_label.place(x=self.width / 2 + 270, y=heading_y + 130, width=120)
ara_label.configure(anchor="center")
fare_label = ttk.Label(self.base_frame, text="Flight Fare -",
font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
, foreground=text_color)
fare_label.place(x=self.width / 2 + 270, y=heading_y + 160, width=120)
fare_label.configure(anchor="center")
# available_label = ttk.Label(self.base_frame, text="Available Seats -",
# font=('Calibri', AppConstant.FONT_SIZE - 5, 'normal'), background=bg_color
# , foreground=text_color)
# available_label.place(x=self.width / 2 + 245, y=heading_y + 190, width=150)
# available_label.configure(anchor="center")
now we will add show the details for selected Flight.
# ============Selected flight=======================
add_flight_detail_frame(self.base_frame, self.color, self.height, self.width)
self.selected_flight_table_detail()
self.add_flight_book_button()
def add_flight_book_button(self):
self.add_flight_book_button1 = RoundedButton(self.base_frame, 150, 110 / 2.56, self.color, "images/button3.png",
"Book Flight",
font=("Lucida Grande", AppConstant.FONT_SIZE - 2),
command=self.book_flight_click)
self.add_flight_book_button1.place(x=1150, y=550)
here is the most important part is book flight logic.
def book_flight_click(self):
flight_no = ""
passenger_id = ""
var = ""
is_name_entered = False
is_flight_tree_focused = False
is_passenger_tree_focused = False
current_item = self.flight_tree.focus()
if current_item == "" or current_item == " ":
var += "Flight Not Selected, "
else:
flight_no = self.flight_tree.item(current_item)["values"][0]
is_flight_tree_focused = True
current_item = self.passenger_tree_view.focus()
if current_item == "" or current_item == " ":
var += "Passenger Not Selected, "
else:
passenger_id = self.passenger_tree_view.item(current_item)["values"][0]
is_passenger_tree_focused = True
#
# current_item = self.passenger_tree_view.focus()
# passenger_id = self.passenger_tree_view.item(current_item)["values"][0]
booking_date = self.cal.get_date()
if is_flight_tree_focused and is_passenger_tree_focused:
conn = Util.connect_db()
cursor = conn.cursor()
key = "BOOKING_LAST_COUNT"
cursor.execute('SELECT value FROM system_setting WHERE key IS ?', (key,))
rows = cursor.fetchone()
print(rows[0])
id_count = Util.convert_string_to_int(rows[0]) + 1
booking_id = get_booing_id(id_count) + str(id_count)
cursor.execute('INSERT INTO booking(booking_id, flight_no, passenger_id, booking_date) VALUES(?,?,?,?)',
(booking_id, flight_no, passenger_id, booking_date))
cursor.execute("UPDATE system_setting SET value = ? WHERE key = ?",
(id_count, key,))
conn.commit()
cursor.close()
var = "Ticket Booked Successfully "
messagebox.showinfo("showinfo", var)
else:
print(var)
messagebox.showerror("showerror", var)
# get booking Id
def get_booing_id(s_id):
passenger_id = "TB"
count = 0
if s_id == 0:
count = 1
while s_id > 0:
count = count + 1
s_id = s_id // 10
count = 3 - count
while count > 0:
passenger_id = passenger_id + "0"
count = count - 1
return passenger_id
At last we will manage closing of window
def on_closing():
root.destroy()
args[0].deiconify()
root.protocol("WM_DELETE_WINDOW", on_closing)
Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 2021 by Programmer Mitra. All Rights Reserved.