Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need Python GUI to show the user input, results and error output LeibnizClass.py class LeibnizPIClass: pi = 0.0 '''Please enter the number of values to
Need Python GUI to show the user input, results and error output LeibnizClass.py class LeibnizPIClass: pi = 0.0 '''Please enter the number of values to be calculated for Pi:''' def __init__(self, user_input): '''comment''' denominator = 1 numerator = 4 counter = 0 while counter < user_input: nextterm = numerator/denominator * (-1) **counter self.pi += nextterm denominator +=2 counter += 1 def areaC(f1, radius): AreaCircle=f1 * radius * radius print("Area Circle= " + "%.2f" %AreaCircle) def CircleC(f1,radius): CircleCircumference=2 * f1 * radius print("Circle Circumference= "+ "%.2f" % CircleCircumference) def VolumeS(f1,radius): VolumeOfSphere=(4/3) * f1 * radius * radius print("Volume Of Sphere= " + "%.2f" %VolumeOfSphere)
LeibnizProgram.py
import LeibnizClass def errorMessages(): """This function contains the reusable error messages.""" print("You entered an invalid value. You must enter a positive integer.") main() def ending(): """Allows the user to run the program again or terminate it.""" print(" " "Type A to run the program again. " "Press Enter to end the program.") runagain = input() if runagain == "A": main() def main(): """This function controls the main thread of the program.""" print("Please enter the number of values to be calculated for Pi: ") response = input() try: user_input = int(response) except ValueError: errorMessages() else: if user_input <= 0: errorMessages() else: f = LeibnizClass.LeibnizPIClass(user_input) print("PI value is: " + str(f.pi)) f1=f.pi #store the pi value to f1 print("Please enter the Radius") r=float(input()) AreaCircle=LeibnizClass.LeibnizPIClass.areaC(f1,r) #this function Calculate the Area of Circle CircleCircumference=LeibnizClass.LeibnizPIClass.CircleC(f1,r) #this function Calculate the Circle Circumference VolumeOfSphere=LeibnizClass.LeibnizPIClass.VolumeS(f1,r) #this function Calculate the Volume Of Sphere ending() main()
GUI Python File
import tkinter # Create a window object and give it a title window = tkinter.Tk() window.title("PI Calculator") window.geometry("600x600") # Create a label and and place it in a grid instruction_lbl = tkinter.Label(window, text="Enter the number of values to be calculated for PI:") instruction_lbl.place(x=10, y=10) # Create a text entry field entry_field = tkinter.Entry(window, width=10) entry_field.place(x=300, y=10) entry_field.focus() # Make an Enter button enter_btn = tkinter.Button(window, text="Go!") enter_btn.place(x=336, y=10) # Create a label and and place it in a grid results_lbl = tkinter.Label(window, text="Results:") results_lbl.place(x=10, y=40) # Create an empty label for displaying the results output_lbl = tkinter.Label(window, text=" ") output_lbl.place(x=10, y=60) # Create an Exit button and place it in the frame exit_btn = tkinter.Button(window, text="Exit") exit_btn.place(x=336, y=60) # Draw the window and start the program window.mainloop()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started