-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_charges.py
More file actions
76 lines (58 loc) · 2.61 KB
/
call_charges.py
File metadata and controls
76 lines (58 loc) · 2.61 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
#Kylie Drawdy
#4/15/24
#Write a GUI application that allows the user to select a rate category, and enter the number of minutes
#of the call into an Entry widget. An info dialog box should display the charge for the call.
import tkinter
import tkinter.messagebox
class LongDistanceGUI:
def __init__(self):
#Create main window
self.main_window = tkinter.Tk()
#Create 2 frames
self.top_frame = tkinter.Frame(self.main_window)
self.middle_frame = tkinter.Frame(self.main_window)
self.bottom_frame = tkinter.Frame(self.main_window)
#Create variable for radio buttons
self.radioVariable = tkinter.IntVar()
#Set default for radio buttons to 1
self.radioVariable.set(1)
#Create radio buttons
self.radiobtn1 = tkinter.Radiobutton(self.top_frame, text = "Daytime", variable = self.radioVariable, value = 1)
self.radiobtn2 = tkinter.Radiobutton(self.top_frame, text = "Evening", variable = self.radioVariable, value = 2)
self.radiobtn3 = tkinter.Radiobutton(self.top_frame, text = "Off-Peak", variable = self.radioVariable, value = 3)
# Pack radio buttons
self.radiobtn1.pack()
self.radiobtn2.pack()
self.radiobtn3.pack()
#Create items for middle frame
self.minuteLabel = tkinter.Label(self.middle_frame, text = "Enter minutes: ")
self.minuteEntry = tkinter.Entry(self.middle_frame, width = 10)
#Pack items for middle frame
self.minuteLabel.pack(side = "left")
self.minuteEntry.pack(side = "left")
#Create submit button
self.displayButton = tkinter.Button(self.bottom_frame, text = "Display Charges", command = self.calcCharges)
#Pack button
self.displayButton.pack()
#pack frames
self.top_frame.pack()
self.middle_frame.pack()
self.bottom_frame.pack()
#Start listening for events
tkinter.mainloop()
def calcCharges(self):
#Get entered value
self.minuteEntry = float(self.minuteEntry.get())
#Determine which radio button was checked and set value
if self.radioVariable.get() == 1:
self.minuteRate = 0.07
elif self.radioVariable.get() == 2:
self.minuteRate = 0.12
elif self.radioVariable.get() == 3:
self.minuteRate = 0.05
#Calculate charges
self.finalCharge = self.minuteRate * self.minuteEntry
#Display results and close window
tkinter.messagebox.showinfo("Total: " + format(self.finalCharge, ',.2f'))
self.main_window.destroy()
longDistance = LongDistanceGUI()