Python Challenge 8 (GUI)

 

Python Challenge 8 (GUI)

 

Costa Fortune Coffee is developing a GUI for their stores. They think a graphical user interface might make the system more user friendly. The system needs to have buttons that users can select, it needs to display the order total when the finish button is clicked and the system should generate a bill in a word document that can be used as a receipt. The bill should display the order number, the items ordered and also the order cost.

They have a basic GUI that runs a function everytime a button is clicked. They have built a function for tea and coffee and one to run the order, update the screen and create a bill. However they need to develop it further to make it compatible with their menu (shown below)....

 

 

The basic code that the coffee shop has is shown below. Run it to check it works then see if you can develop it further to work with the coffee shop menu shown.


 

 

cost=0
order=[]
order_number=0

#function that runs when coffee is selected
def coffee():
    print("Coffee ordered")
    order.append("Coffee")
    global cost
    coffeecost=1.55
    cost=cost+coffeecost
    print(cost)
    print(order)
#function that runs when tea is selected
def tea():
    print("Tea ordered")
    order.append("Tea")
    global cost
    teacost=1.75
    cost=cost+teacost
    print(cost)
    print(order)
#function that runs when finish order is selected
def finish():
    global order_number
    global cost
    order_number=order_number+1
    print("Order number: ", order_number)
    print("Your order is: ", order)
    print("Payment due: £", cost)
    labela.configure(text=order_number)
    labelb.configure(text=order)
    labelc.configure(text=cost)
    file=open('your_bill' + str(order_number) + '.doc','w')
    file.write("Your order:\n")
    file.write("Order = " + repr(order) + "\n")
    file.write("Cost = £" + repr(cost) + "\n")
    file.close()
    cost=0
    order.clear()
    
#code to set up your window
from tkinter import*
from tkinter import ttk
rw=Tk()
btn1=ttk.Button(rw,text="Coffee")
btn1.pack()
btn1.config(command=coffee)
btn2=ttk.Button(rw,text="Tea")
btn2.pack()
btn2.config(command=tea)
btn3=ttk.Button(rw,text="Finish Order")
btn3.pack()
btn3.config(command=finish)
labela=ttk.Label(rw,text="Order Number")
labela.pack()
labelb=ttk.Label(rw,text="Order")
labelb.pack()
labelc=ttk.Label(rw,text="Cost")
labelc.pack()

 

EXT: Other improvements could include.....

Adding a title to the GUI.

importing an image onto the GUI.

Changing the colour of the GUI.

Defining the GUI size.

Adding a running total cost of all orders so they know how much money they have made.

A record of products ordered so they know how many of each product they have sold.