# Imports all of tkinter and its variables/functions
from tkinter import*
# Lets square root function be used
from math import sqrt as sqrt
# imports messagebox and can be called as messagebox (instead of tkinter.messagebox)
import tkinter.messagebox as messagebox
gravityCount = 0
pressureCount = 0
# Creates a TK/GUI Screen called calculator
calculator = Tk()
# Titles it
calculator.title("Terminal Velocity Calculator")
# Sets width and height
calculator.geometry("400x400")
# Creates the function that happens when you click the button
def submit():
global numberGravity
global numberPressure
# Retrieves the number inputted in the Mass Entry
m = numberMass.get()
g = numberGravity.get()
p = numberPressure.get()
a = numberArea.get()
# Calculate Terminal Velocity
terminalVelocity = sqrt((4*m*g)/(p*a))
# Show an info messagebox displaying the Terminal Velocity
messagebox.showinfo("Terminal Velocity", terminalVelocity)
def isStandardGravity():
# imports count variable from outside this function
global gravityCount
# Get value from gravity buttons
gravityValue = gravityS.get()
# If no is selected, then display options to change Gravity
if gravityValue == "No" and gravityCount == 0:
# Stops repeated additoins of the entry and label
gravityCount = gravityCount + 1
gravity = Frame()
gravity.pack(pady=10)
Label(gravity, text='Gravity = ').pack(side=LEFT)
# Variable contains a decimal
numberGravity = DoubleVar(None)
Entry(gravity, textvariable=numberGravity,).pack(side=LEFT)
elif gravityValue == "Yes" and gravityCount == 1:
####### INSERT CODE FOR MAKING THE ENTRY DISAPPEAR
elif gravityValue == "Yes" and gravityCount == 0:
numberGravity = DoubleVar(None)
numberGravity.set(9.8)
def isStandardPressure():
# imports count variable from outside this function
global pressureCount
# Get value from gravity buttons
pressureValue = pressureS.get()
# If no is selected, then display options to change Gravity
if pressureValue == "No" and pressureCount == 0:
# Stops repeated additoins of the entry and label
pressureCount = pressureCount + 1
pressure = Frame()
pressure.pack(pady=10)
Label(pressure, text='Pressure = ').pack(side=LEFT)
# Variable contains a decimal
numberPressure = DoubleVar(None)
Entry(pressure, textvariable=numberPressure,).pack(side=LEFT)
elif pressureValue == "Yes" and pressureCount == 1:
####### INSERT CODE FOR MAKING THE ENTRY DISAPPEAR
elif pressureValue == "Yes" and pressureCount == 0:
numberPressure = DoubleVar(None)
numberPressure.set(1.22)
# Invisible frame that will hold the elemts you select it to
mass = Frame()
# Pack the frame and where you want it to be
mass.pack(pady=10)
# Creates Label and puts it in the Frame mass
Label(mass, text='Mass = ').pack(side=LEFT)
# Create the variable for the entry field and leave it blank
numberMass = DoubleVar(None)
# Creates the entry field
Entry(mass, textvariable=numberMass).pack(side=LEFT)
area = Frame()
area.pack()
Label(area, text="Surface Area = ").pack(side=LEFT)
numberArea = DoubleVar(None)
Entry(area, textvariable=numberArea).pack(side=LEFT)
# Buttons for Gravity
standardGravity = Frame()
standardGravity.pack(pady=10)
Label(standardGravity, text="Standard Gravity").pack(side=TOP)
gravityS = StringVar()
gravityS.set(None)
# Create two radio buttons labeled Yes/No and check to see if standard gravity should be used
Radiobutton(standardGravity, text="Yes", value="Yes", variable = gravityS, command=isStandardGravity).pack()
Radiobutton(standardGravity, text="No", value="No", variable = gravityS, command=isStandardGravity).pack()
# Buttons for Air Pressure
standardPressure = Frame()
standardPressure.pack()
Label(standardPressure, text="Standard Pressure").pack(side=TOP)
pressureS = StringVar()
pressureS.set(None)
# Create two radio buttons labeled Yes/No and check to see if standard gravity should be used
Radiobutton(standardPressure, text="Yes", value="Yes", variable = pressureS, command=isStandardPressure).pack()
Radiobutton(standardPressure, text="No", value="No", variable = pressureS, command=isStandardPressure).pack()
# Create a frame for the button
button = Frame()
# Place the frame at the very bottom
button.pack(pady=10, side=BOTTOM)
# Create a button that calls the submit command when clicked
Button(button, text="Submit", command=submit).pack()
# The calculator window is constantly checked for inputs by user
calculator.mainloop()
Thanks for the help.

New Topic/Question
Reply




MultiQuote






|