-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClass Notes_04_26_2021.py
More file actions
60 lines (45 loc) · 1.78 KB
/
Class Notes_04_26_2021.py
File metadata and controls
60 lines (45 loc) · 1.78 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
#####################
## Dalton Murray #
## 04/26/20201 #
## Class notes #
#####################
import tkinter
class Gui():
def __init__(self):
self.gui = tkinter.Tk()
self.gui.title("Calculator")
self.gui.geometry("250x250")
self.mathType = tkinter.StringVar()
self.firstVar = tkinter.StringVar()
self.secondVar = tkinter.StringVar()
self.thirdVar = tkinter.StringVar()
self.entry1 = tkinter.Entry(self.gui, textvariable=self.mathType)
self.entry1.pack()
self.entry2 = tkinter.Entry(self.gui, textvariable=self.firstVar)
self.entry2.pack()
self.entry3 = tkinter.Entry(self.gui,textvariable=self.secondVar)
self.entry3.pack()
self.entry4 = tkinter.Entry(self.gui, textvariable=self.thirdVar)
self.entry4.pack()
def myFunc():
firstNum = self.firstVar.get()
secondNum = self.secondVar.get()
mathType = self.mathType.get()
mathType = mathType.lower()
if mathType == "add":
thirdVar = float(firstNum) + float(secondNum)
elif mathType == "subtract":
thirdVar = float(firstNum) - float(secondNum)
elif mathType == "divide":
thirdVar = float(firstNum) / float(secondNum)
elif mathType == "multiply":
thirdVar = float(firstNum) * float(secondNum)
self.label1.config(text=thirdVar)
self.thirdVar.set(thirdVar)
self.label1 = tkinter.Label(self.gui, text="")
self.label1.pack()
self.btn1 = tkinter.Button(self.gui, text="Click me", command=myFunc, width=15, height=5)
self.btn1.pack()
tkinter.mainloop()
if __name__ == "__main__":
myGui = Gui()