tkinter trig calculator code example
Example: tkinter trig calculator
import tkinter as tk
from tkinter import ttk
window = tk.Tk()
v = tk.IntVar()
v.set(1)
x1String = "x1: "
x2String = "x2: "
y1String = "y1: "
y2String = "y2: "
window.geometry("640x860")
submit = tk.Button(window, text="Run Equasion",command = lambda:run())
inputtxt = tk.Text(window, height = 10,
width = 25,
bg = "light yellow")
greeting = tk.Label(text="Math Calculator")
greeting.pack()
entry = tk.Entry(fg="yellow", bg="blue", width=50)
lineBr = ttk.Separator(window, orient='horizontal')
lineBr.pack(fill='x')
#App code after here
Formulas = [("Distance Formula", 101),
("Pythagorean Theorem", 102),
("Area of a Sphere", 103),
("Volume of a Sphere", 104),
("Midpoint Formula", 105)]
def ShowChoice():
global submit
#print(string)
if v.get() == 101:
inputtxt.insert(tk.END, "distance()")
elif v.get() == 102:
inputtxt.insert(tk.END, "pathaga()")
elif v.get() == 103:
inputtxt.insert(tk.END, "AreaSphere()")
elif v.get() == 104:
inputtxt.insert(tk.END, "VolumeSphere()")
elif v.get() == 105:
inputtxt.insert(tk.END, "Midpoint()")
return v.get()
def run():
return print(inputtxt.get("1.0", "end"))
for mathEqu, val in Formulas:
tk.Radiobutton(window,
text=mathEqu,
indicatoron = 0,
width = 20,
padx = 20,
variable=v,
command=ShowChoice,
value=val).pack(anchor=tk.W)
tk.Label(text="\n").pack()
inputtxt.pack()
submit.pack()
#x1 = x1Box.get("1.0", "end-1c")
window.mainloop()