Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasicGUI.py
More file actions
Latest commit
183 lines (155 loc) · 5.89 KB
/
Copy pathbasicGUI.py
File metadata and controls
183 lines (155 loc) · 5.89 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# -*- coding: utf-8 -*-
importtkinterastk
fromtkinterimport*
fromtkinterimportttk
fromtrigimportgivenLengths, givenPoints
fromC2FimportC_to_F_converter, F_to_C_converter, k_to_c_converter, c_to_k_converter
fromdictionaryimportdictionary
fromPILimportImageTk, Image
fromcalcimportstartCalc
#Create new label with output value on specified page
defnewLabel(strOut, pageNum):
if(pageNum==page3):
wrapNum=500
else:
wrapNum=0
Label(pageNum, text=strOut, wraplength=wrapNum).pack()
#Function called when button pressed if points of triangle are entered (page1)
defenterValuesPoints():
#Get triangle type from givenLengths in main.py
finalAnswerPoints=givenPoints(getx1.get(), gety1.get(), getx2.get(), gety2.get(), getx3.get(), gety3.get())
print(finalAnswerPoints)
#Add lengths and triangle type as new labels in GUI
newLabel("Side 1: "+str(finalAnswerPoints[0]) +
"\nSide 2: "+str(finalAnswerPoints[1]) +
"\nSide 3: "+str(finalAnswerPoints[2]) +
"\nType: "+str(finalAnswerPoints[3]),
page1)
#Function called when button pressed if lengths of sides are entered (page1)
defenterValuesLength():
print("LENGTHS:")
print(str(getSide1) +str(getSide2) +str(getSide3))
#Get triangle type from givenLengths using main.py
finalAnswerLength=givenLengths(getSide1.get(), getSide2.get(), getSide3.get())
print(finalAnswerLength)
#Add triangle type as a new label in GUI
newLabel(finalAnswerLength, page1)
#Creates input field/labels/buttons for length input (page1)
deflengthInput():
#Labels/input fields for GUI (side lengths)
forxinrange (1, 4):
newLabel("Side "+str(x), page1)
if(x==1):
sideNeeded=getSide1
elif(x==2):
sideNeeded=getSide2
else:
sideNeeded=getSide3
Entry(page1, textvariable=sideNeeded).pack()
#Submit button in GUI (side lengths)
Button(page1, text="Submit Lengths", command=enterValuesLength, fg="white", bg="black").pack()
#Creates input field/labels/buttons for point input (page1)
defpointInput():
#Labels/input fields for GUI (points given)
forxinrange (1, 4):
if(x==1):
nums="x1", "y1"
textVar=getx1, gety1
elif(x==2):
nums="x2", "y2"
textVar=getx2, gety2
elif(x==3):
nums="x3", "y3"
textVar=getx3, gety3
newLabel(nums[0], page1)
Entry(page1, textvariable=textVar[0]).pack()
newLabel(nums[1], page1)
Entry(page1, textvariable=textVar[1]).pack()
Button(page1, text="Submit Points", command=enterValuesPoints, fg="white", bg="black").pack()
#Function called when button pressed if degrees entered (page2)
defenterDegree(dType):
#dType 1 = C to F
#dType 2 = F to C
#dType 3 = K to C
#dType 4 = C to K
defwhatToDo(convType, strType, strInv):
finalDeg=convType(getC.get())
print(finalDeg)
newLabel(str(getC.get()) +"°"+strType+" = "+str(finalDeg) +"°"+strInv, page2) #str(finalF) + "°F", page2)
if(dType==1):
whatToDo(C_to_F_converter, "C", "F")
elif(dType==2):
whatToDo(F_to_C_converter, "F", "C")
elif(dType==3):
whatToDo(k_to_c_converter, "K", "C")
else:
whatToDo(c_to_k_converter, "C", "K")
#Creates input field/labels/buttons for degree input (page2)
'''v = tk.IntVar()'''
defdegreeInput():
newLabel("Degrees to convert", page2)
mEntry=Entry(page2, textvariable=getC).pack()
Button(page2, text="Submit °C Value To °F", command=lambda : enterDegree(1), fg="white", bg="black").pack()
Button(page2, text="Submit °F Value To °C", command=lambda : enterDegree(2), fg="white", bg="black").pack()
Button(page2, text="Submit °K Value To °C", command=lambda : enterDegree(3), fg="white", bg="black").pack()
Button(page2, text="Submit °C Value To °K", command=lambda : enterDegree(4), fg="white", bg="black").pack()
'''tk.Radiobutton(mGUI, text="Python", padx = 20, variable=v, value=1).pack(anchor=tk.W)'''
#Function called when button pressed to enter word (page3)
defenterWord(event=None):
wordDef= ((str(dictionary(getWord.get())).strip('[]'))).strip("''")
if(wordDef=="Not found in dictionary."):
newLabel(wordDef, page3)
else:
newLabel(getWord.get() +" = "+wordDef, page3)
print(wordDef)
print(getWord.get())
#Creates input field/labels/buttons for word input (page3)
defwordInput():
newLabel("Word: ", page3)
Entry(page3, textvariable=getWord).pack()
WI=Button(page3, text="Submit Word", command=enterWord, fg="white", bg="black")
WI.pack()
#Works good enough
defmainCalc():
Button(page4, text="Open Calculator", command=startCalc, fg="white", bg="black").pack()
#Setting up GUI (and tabs) and variables for input
mGUI=tk.Tk()
#mGUI.iconbitmap('icon.ico')
nb=ttk.Notebook(mGUI)
page1=ttk.Frame(nb)
page2=ttk.Frame(nb)
page3=ttk.Frame(nb)
page4=ttk.Frame(nb)
nb.add(page1, text="Triangle Calculator")
nb.add(page2, text="Degree Converter")
nb.add(page3, text="Dictionary")
nb.add(page4, text="Calculator")
nb.pack(expand=1, fill="both")
#Values if given lengths
getSide1=IntVar()
getSide2=IntVar()
getSide3=IntVar()
#Values if given points
getx1=IntVar()
gety1=IntVar()
getx2=IntVar()
gety2=IntVar()
getx3=IntVar()
gety3=IntVar()
#Values for degree conversion
getC=IntVar()
getF=IntVar()
#Values for Dictionary
getWord=StringVar()
#Run functions to display in window
lengthInput()
pointInput()
degreeInput()
wordInput()
mainCalc()
mGUI.bind('<Return>', enterWord)
#Run/setup GUI
mGUI.geometry("600x900")
mGUI.configure(background="green")
mGUI.title("A bunch of things that seem useful")
mGUI.mainloop()