-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicket.py
More file actions
80 lines (60 loc) · 2.12 KB
/
Ticket.py
File metadata and controls
80 lines (60 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Import libraries
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("600x500")
root.configure(background="#DF4A44")
# Creating a variables for prices
sc = 40
mv = 75
th = 100
# Creating Tkinter widgets
var = StringVar()
e1 = Entry(root, width=10)
e1.grid(row=0, column=1)
cat = ttk.Combobox(root, textvariable=var, width=10, value=["Soccer", "Movie", "Theater"])
cat.grid(row=3, column=1)
num = ttk.Spinbox(root, from_=0, to=100, state="readonly")
num.grid(row=2, column=1)
l1 = Label(root, text="Cellphone number:")
l1.grid(row=0, column=0, sticky=W)
l2 = Label(root, text="Ticket Category:")
l2.grid(row=4, column=0, sticky=W)
l3 = Label(root, text="Number of tickets:")
l3.grid(row=4, column=0, sticky=W)
ans = Label(root)
ans.grid(row=14, column=0)
#Creating class
class TicketSales:
"""Handles ticket sales calculations."""
VAT_RATE = 0.14
PRICES = {
"Soccer": 40,
"Movie": 75,
"Theater": 100
}
@classmethod
def calculate_cost(cls, category: str, quantity: int) -> float:
"""Calculate total cost including VAT."""
base_price = cls.PRICES.get(category, 0)
return (base_price * quantity) * (1 + cls.VAT_RATE)
# Creates function for button
def calc():
# Passes through class
total = TicketSales.calculate_cost(cat.get(), int(num.get()))
# Decision tree
if cat.get() == "Soccer":
scprice = sc * int(num.get()) + (14/100)
ans.config(text="Price:"+ str(scprice) + "\n" + "tickets:"+str(num.get()) + "\n" +"Number:"+ str(e1.get()))
if cat.get() == "Movie":
mvprice = mv * int(num.get()) + (14/100)
ans.config(text="Price:"+ str(mvprice) + "\n" + "tickets:"+str(num.get()) + "\n" +"Number:"+ str(e1.get()))
if cat.get() == "Theater":
thprice = th * int(num.get()) + (14/100)
ans.config(text="Price:"+ str(thprice) + "\n" + "tickets:"+str(num.get()) + "\n" +"Number:"+ str(e1.get()))
# function
#Creating button
btn = Button(root, text="calculate", command=calc, width=20, height=1)
btn.grid(row=8, column=0)
# Adds widgets
root.mainloop()