Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a graphical user interface that is suitable for use with the program you

ID: 3819276 • Letter: C

Question

 Create a graphical user interface that is suitable for use with the program you wrote for below program.  Your interface should reflect both the information you need to prompt for and what the output would look like based on your answer to below program.  #!/usr/bin/python  import math  class PI:    pi=0     def calculate_pi(self,n):        sum=0        for j in range(0,n):            sum = sum + (math.pow(-1,j)/((2*j)+1)) #summation of the Leibniz series            pi = 4 * sum        return float(pi) #return number     def use_pi(self,r,pi): #shows usage of pi attribute in class        radius=r        area=pi*radius*radius #calculates Circle area        return float(area)  #print the output obj=PI() n = input('Enter number of values to be used in the pi calculation : ') p=obj.calculate_pi(int(n)) print (" pi = ", p) rad = input(' Enter radius of Circle : ') print (" Area of Circle = ", obj.use_pi(int(rad),p)) 

Explanation / Answer

# Create a graphical user interface that is suitable for use with
# the program you wrote for below program. Your interface should
# reflect both the information you need to prompt for and what the
# output would look like based on your answer to below program.

import math
from tkinter import *
import tkMessageBox

class PI:
pi = 0

def calculate_pi(self,n):
    sum = 0
    for j in range(0,n):
      sum += (math.pow(-1,j)/((2*j)+1))
      pi = 4 * sum
    return float(pi)

def use_pi(self,r,pi):
    radius = r
    area = pi * radius * radius
    return float(area)


def call_back():
obj = PI()
result = ""
print "The value of pi is", str(obj.calculate_pi(int(i1.get()))), " "
if (i1.get() != ""):
    result += "The value of pi is " + str(obj.calculate_pi(int(i1.get()))) + " "
if (i2.get() != ""):
    result += "The area of the circle is " + str(obj.use_pi(int(i2.get()),obj.calculate_pi(int(i1.get())))) + " "
tkMessageBox.showinfo( "Result", result )

# Window
top_window = Tk()

# Input 1
l1 = Label(
top_window, text="Number of values to use in PI Calculation " )
i1 = Entry(top_window, bd=5)
l1.grid(row=0, column=0, padx=10, pady=10)
i1.grid(row=0, column=1, padx=10, pady=10)


# Input 2
l2 = Label(
top_window, text="Radius of the circle " )
i2 = Entry(top_window, bd=5)
l2.grid(row=1, column=0, padx=10, pady=10)
i2.grid(row=1, column=1, padx=10, pady=10)


b1 = Button(
top_window, text = "Calculate", command = call_back )
b1.grid(row=2, column=0, padx=10, pady=10)

top_window.mainloop()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote