You are on page 1of 2

Problem Solution;_

We solving this problem by using tkinter library

import tkinter as tk

book_database = {
"Book1": 10.99,
"Book2": 8.50,
"Book3": 12.75,
"Book4": 15.00,
}

class BookFormApp:
def __init__(self, root):
self.root = root
self.root.title("Book Form")

self.title_label = tk.Label(root, text="Book Title:")


self.title_label.pack()

self.title_entry = tk.Entry(root)
self.title_entry.pack()

self.find_price_button = tk.Button(root, text="Find Price", command=self.find_price)


self.find_price_button.pack()

self.price_label = tk.Label(root, text="Price:")


self.price_label.pack()

self.quantity_label = tk.Label(root, text="Quantity:")


self.quantity_label.pack()

self.quantity_entry = tk.Entry(root)
self.quantity_entry.pack()

self.find_total_button = tk.Button(root, text="Find Total Amount",


command=self.find_total_amount)
self.find_total_button.pack()

self.total_label = tk.Label(root, text="Total Amount:")


self.total_label.pack()

def find_price(self):
book_title = self.title_entry.get()
if book_title in book_database:
price = book_database[book_title]
self.price_label.config(text="Price: ${:.2f}".format(price))
else:
self.price_label.config(text="Price: Not Found")

def find_total_amount(self):
book_title = self.title_entry.get()
quantity = self.quantity_entry.get()

if book_title in book_database:
try:
quantity = int(quantity)
price = book_database[book_title]
total_amount = price * quantity
self.total_label.config(text="Total Amount: ${:.2f}".format(total_amount))
except ValueError:
self.total_label.config(text="Total Amount: Invalid Quantity")
else:
self.total_label.config(text="Total Amount: Book Not Found")

if __name__ == "__main__":
root = tk.Tk()
app = BookFormApp(root)
root.mainloop()

You might also like