0% found this document useful (0 votes)
20 views2 pages

From Tkinter Import

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

From Tkinter Import

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

from tkinter import *

from tkinter import ttk

root = Tk()

# dictionary
prices = {"COCA COLA": 8, "PEPSI COLA": 6, "ROYAL SODA": 5}

# FUNCTION
def add():
selected_drink = ds.cget("text")
ordered_drinks = otr.cget("text")
price = prices[selected_drink]

ordered_drinks += f"{selected_drink} ....... {price}$\n"


otr.configure(text=ordered_drinks)

total = float(otl.cget("text").replace("TOTAL: ", "").replace("$", ""))


total += price
otl.configure(text=f"TOTAL: {total}$")

def remove():
selected_drink = ds.cget("text")
ordered_drinks = otr.cget("text")
price = prices[selected_drink]

if f"{selected_drink} ....... {price}$" in ordered_drinks:


ordered_drinks = ordered_drinks.replace(f"{selected_drink} ....... {price}$\n", "")
otr.configure(text=ordered_drinks)

total = float(otl.cget("text").replace("TOTAL: ", "").replace("$", ""))


total -= price
otl.configure(text=f"TOTAL: {total}$")

def pay():
import tkinter as tk

class CashierMachine:
def __init__(self, root):
self.root = root
self.products = []

# Create GUI elements


self.t_label = tk.Label(root, text="TOTAL PRICE", font=("Sans Serif", "11", "bold"))
self.t_label.pack()
self.t_entry = tk.Entry(root)
self.t_entry.pack()

self.csh_label = tk.Label(root, text="ENTER CASH", font=("Sans Serif", "11", "bold"))


self.csh_label.pack()
self.csh_entry = tk.Entry(root)
self.csh_entry.pack()

self.chn_button = tk.Button(root, text="COMPUTE CHANGE", font=("Sans Serif", "11", "bold"),


command=self.add_product)
self.chn_button.pack()

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


self.total_label.pack()

self.r_button = tk.Button(root, text="PRINT RECEIPT", font=("Sans Serif", "12",


"bold"),command=self.print_receipt)
self.r_button.pack()

self.receipt_text = tk.Text(root, height=10, width=40)


self.receipt_text.pack()

def add_product(self):
total = float(self.t_entry.get())
cash = float(self.csh_entry.get())

self.products.append((total, cash))

self.calculate_total()

def calculate_total(self):
v1 = float(self.t_entry.get())
v2 = float(self.csh_entry.get())
diff = v2 - v1
self.total_label.config(text="Total: ${:.2f}".format(diff), font= ("Times New Roman", "12", "bold"))

def print_receipt(self):
receipt = "************\nRECEIPT\n************\n\n"

for total, cash in self.products:


receipt += "Total: ${:.2f}\nCash: ${:.2f}\n\n".format(total, cash)

total_cash = self.total_label
total_cash.configure(text=f"TOTAL CHANGE: " + str(total_cash))
receipt += "********"

self.receipt_text.delete("1.0", tk.END)
self.receipt_text.insert(tk.END, receipt)

# Reset the cashier machine


self.products = []
self.total_label.config(text="Total: 0.00$")

self.t_entry.delete(0, tk.END)
self.csh_entry.delete(0, tk.END)

# Create the main window


root = tk.Tk()
root.title("Cashier Machine")

# Create the cashier machine instance


cashier_machine = CashierMachine(root)

# Run the main event loop


root.mainloop()

def c1():
ds.configure(text="COCA COLA", font=("Verdana", "11", "bold"), anchor=CENTER)

def c2():
ds.configure(text="PEPSI COLA", font=("Verdana", "11", "bold"), anchor=CENTER)

def c3():
ds.configure(text="ROYAL SODA", font=("Verdana", "11", "bold"), anchor=CENTER)

# main
mainf = ttk.Frame(root, width=800, height=800, style="df.TFrame")
mainf.grid(row=0, column=0, sticky=NSEW)

# mainframes
menuf = ttk.Frame(mainf, relief=SUNKEN, borderwidth=3)
menuf.grid(row=0, column=0, sticky=NSEW)
ordrf = ttk.Frame(mainf, style="df.TFrame", relief=GROOVE, borderwidth=3)
ordrf.grid(row=0, column=2, sticky=NSEW)

# dishframe
cd = ttk.Frame(menuf, style="mf.TFrame", relief=RAISED, borderwidth=3)
cd.grid(row=0, column=0, padx=3, pady=15, sticky=N)
c1f = ttk.Frame(menuf, style="mf.TFrame", relief=RAISED, borderwidth=3)
c1f.grid(row=1, column=0, padx=3, pady=15, sticky=NSEW)
c2f = ttk.Frame(menuf, style="mf.TFrame", relief=RAISED, borderwidth=3)
c2f.grid(row=2, column=0, padx=3, pady=15, sticky=NSEW)
c3f = ttk.Frame(menuf, style="mf.TFrame", relief=RAISED, borderwidth=3)
c3f.grid(row=3, column=0, padx=3, pady=15, sticky=NSEW)
cds = ttk.Frame(menuf, style="mf.TFrame", relief=RAISED, borderwidth=3)
cds.grid(row=4, column=0, padx=3, pady=15, sticky=NSEW)

# MENULABEL
ml = ttk.Label(cd, text="\t DRINKS ")
ml.config(font=("Verdana", "14", "bold"), anchor=CENTER)
ml.grid(row=0, column=0, pady=15, sticky="NSEW")
m1 = ttk.Label(c1f, text="\tCOCA-COLA ........ 8$\t", font=("Verdana", "10", "bold"))
m1.grid(row=1, column=0, pady=15, sticky="NSEW")
m2 = ttk.Label(c2f, text="\tPEPSI COLA ........ 6$\t", font=("Verdana", "10", "bold"))
m2.grid(row=2, column=0, pady=15, sticky="NSEW")
m3 = ttk.Label(c3f, text="\tROYAL SODA ....... 5$\t", font=("Verdana", "10", "bold"))
m3.grid(row=3, column=0, pady=15, sticky="NSEW")
ds = ttk.Label(cds)
ds.grid(row=4, column=0, pady=15, sticky="NSEW")

# ORDER FRAME
od = ttk.Label(ordrf, text=" ORDERED DRINKS ")
od.config(font=("Verdana", "14", "bold"), relief=SUNKEN, borderwidth=5, anchor=CENTER)
od.grid(row=0, column=0, columnspan=1, sticky=NSEW)
otr = ttk.Label(ordrf, text="")
otr.config(font=("Verdana", "8", "bold"), relief=SUNKEN, borderwidth=5)
otr.grid(row=1, column=0, rowspan=3, sticky=NSEW)
otl = ttk.Label(ordrf, text="TOTAL: 0.00$")
otl.config(font=("Verdana", "10", "bold"), relief=SUNKEN, borderwidth=5)
otl.grid(row=3, column=0, sticky=EW)
otl = ttk.Label(ordrf, text="TOTAL: 0.00$")
otl.config(font=("Verdana", "10", "bold"), relief=SUNKEN, borderwidth=5)
otl.grid(row=3, column=0, sticky=EW)

# butt
m1b = ttk.Button(c1f, text="SELECT", style="txt.TButton", command=c1)
m1b.grid(row=1, column=1, sticky=NSEW)
m2b = ttk.Button(c2f, text="SELECT", style="txt.TButton", command=c2)
m2b.grid(row=2, column=1, sticky=NSEW)
m3b = ttk.Button(c3f, text="SELECT", style="txt.TButton", command=c3)
m3b.grid(row=3, column=1, sticky=NSEW)
ab = ttk.Button(ordrf, text="ADD ITEM", style="txt.TButton", command=add)
ab.grid(row=4, column=0, sticky="EW")
rb = ttk.Button(ordrf, text="REMOVE", style="txt.TButton", command=remove)
rb.grid(row=5, column=0, sticky="EW")
pb = ttk.Button(ordrf, text="PAY", style="txt.TButton", command=pay)
pb.grid(row=6, column=0, sticky="EW")

# configs
c = ttk.Style()
c.configure("mf.TFrame", background="#2B2A4C")
c.configure("mnf.TFrame", background="#EEE2DE")
c.configure("df.TFrame", background="#EA906C")
c.configure("of.TFrame", background="#B31312")
c.configure("txt.TButton", font=("Helvetica", "8", "bold"), background="#EA906C")

ordrf.columnconfigure(0, weight=1)
ordrf.rowconfigure(2, weight=1)

root.mainloop()

You might also like