-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.1 tip_gui.py
More file actions
62 lines (44 loc) · 1.82 KB
/
Copy path1.1 tip_gui.py
File metadata and controls
62 lines (44 loc) · 1.82 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
# This code still needs improvement, it only shows the advantages
# of using a GUI
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
win.geometry("250x300")
win.title("Tips Calculator")
win.resizable(0,0)
def show_total():
"""Calculates and displays into the GUI the total value to pay"""
if tip_cost.get() == "No tip":
total_label.configure(text= "The total bill is {}".format(entry_value.get()))
else:
entry1_value = int(entry_value.get()) # turn entry into an integer
tip_value = int(tip_cost.get()) / 100
def show_total_calc():
total = entry1_value + (entry1_value * tip_value)
total_label.configure(text= "The total bill is {}".format(total))
if tip_value == 0.05:
show_total_calc()
elif tip_value == 0.10:
show_total_calc()
elif tip_value == 0.15:
show_total_calc()
label1 = ttk.Label(win, text = "Tip Calculator", font = ("arial", "15", "bold"))
label1.pack(padx= "20", pady = "20")
label2 = ttk.Label(win, text= "Enter the cost of the bill:")
label2.pack()
entry_value = tk.StringVar()
entry = ttk.Entry(win, width = "8", textvariable = entry_value)
entry.pack()
label3 = ttk.Label(win, text ="Select percentage of tip:")
label3.pack(pady = 10)
tip_cost = tk.StringVar()
tip_value = ttk.Combobox(win, state = "readonly", textvariable = tip_cost)
tip_value['values'] = ("No tip", "5", "10", "15")
tip_value.current(1)
tip_value.pack()
calc_button = tk.Button(win, text = "CALCULATE BILL", width = "20",
bg = "red", fg = "white", command = show_total)
calc_button.pack(padx = "20", pady = "20")
total_label = ttk.Label(win, text = "", font = ("arial", "14"))
total_label.pack()
win.mainloop()