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

Below is my code i wrote and i keep getting this error ( Exception in Tkinter ca

ID: 3716324 • Letter: B

Question

Below is my code i wrote and i keep getting this error ( Exception in Tkinter callback Traceback (most recent call last):
__init__.py", line 1699, in __call__
    return self.func(*args)
Right_Triangle.py", line 66, in calc_ans
    self.SideC_value.set(math.sqrt(self.SideA**2 + self.SideB**2))
AttributeError: 'Pythagorean' object has no attribute 'SideC_value')

this is the question

# This program uses a GUI to get three test
# scores and display their average.

import tkinter
import math


class Pythagorean:
    def __init__(self):
        self.main_window = tkinter.Tk()
        self.main_window.title('Right Triangle Calculator')

        # Create the Four frames.
        self.SideA_frame = tkinter.Frame(self.main_window)
        self.SideB_frame = tkinter.Frame(self.main_window)
        self.SideC_frame = tkinter.Frame(self.main_window)
        self.tri_frame = tkinter.Frame(self.main_window)
        self.button_frame = tkinter.Frame(self.main_window)

        # Create and pack the widgets for Side A.
        self.SideA_label = tkinter.Label(self.SideA_frame,
                                         text='Side A:')
        self.SideA_entry = tkinter.Entry(self.SideA_frame,
                                         width=35)
        self.SideA_label.pack(side='left')
        self.SideA_entry.pack(side='left')

        # Create and pack the widgets for Side B.
        self.SideB_label = tkinter.Label(self.SideB_frame,
                                         text='Side B:')
        self.SideB_entry = tkinter.Entry(self.SideB_frame,
                                         width=35)
        self.SideB_label.pack(side='left')
        self.SideB_entry.pack(side='left')
      
        # Create and pack the widgets for Side C.
        self.SideC_label = tkinter.Label(self.SideC_frame,
                                         text='Side C:')
        self.SideC_entry = tkinter.Entry(self.SideC_frame,
                                         width=35)
        self.SideC_label.pack(side='left')
        self.SideC_entry.pack(side='left')

        # Create and pack the widgets for the calculator.
        self.calc_button = tkinter.Button(self.tri_frame,text='Calculate', command=self.calc_ans)
        self.quit_button = tkinter.Button(self.button_frame, text='Exit', command=self.main_window.destroy)
        self.calc_button.pack(side='right')
        self.quit_button.pack(side='right')

      
        # Pack the frames.
        self.SideA_frame.pack()
        self.SideB_frame.pack()
        self.SideC_frame.pack()
        self.tri_frame.pack()
        self.button_frame.pack()

        # Start the main loop.
        tkinter.mainloop()

    def calc_ans(self):
        self.SideA = float(self.SideA_entry.get())
        self.SideB = float(self.SideA_entry.get())
      
        #Calculate the square root of boths sides
        self.SideC_value.set(math.sqrt(self.SideA**2 + self.SideB**2))
      
        return self
  

Pyth_The = Pythagorean()

Create a GUI program that calculates the hypotenuse of a right triangle after the user enters the lengths of the two short sides and clicks the Calculate button. GUI RightTriangleCalculatot Side A: 100 Side 8: 100 Side C: 141.421 Calculate Exit Specifications Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: c2 = a2 + b2 .As a result, you can calculate side C like this Side C should be rounded to a maximum of 3 decimal places.

Explanation / Answer

The corrected code for the above question is implemented below.

Overall code is correct, but slight difference is there.

Please go through it and check your code once again.

# This program uses a GUI to get three test
# scores and display their average.

import tkinter
import math


class Pythagorean:
    def __init__(self):
        self.main_window = tkinter.Tk()
        self.main_window.title('Right Triangle Calculator')

        # Create the Four frames.
        self.SideA_frame = tkinter.Frame(self.main_window)
        self.SideB_frame = tkinter.Frame(self.main_window)
        self.SideC_frame = tkinter.Frame(self.main_window)
        self.tri_frame = tkinter.Frame(self.main_window)
        self.button_frame = tkinter.Frame(self.main_window)

        # Create and pack the widgets for Side A.
        self.SideA_label = tkinter.Label(self.SideA_frame,
                                         text='Side A:')
        self.SideA_entry = tkinter.Entry(self.SideA_frame,
                                         width=35)
        self.SideA_label.pack(side='left')
        self.SideA_entry.pack(side='left')

        # Create and pack the widgets for Side B.
        self.SideB_label = tkinter.Label(self.SideB_frame,
                                         text='Side B:')
        self.SideB_entry = tkinter.Entry(self.SideB_frame,
                                         width=35)
        self.SideB_label.pack(side='left')
        self.SideB_entry.pack(side='left')
      
        # Create and pack the widgets for Side C.
        self.SideC_label = tkinter.Label(self.SideC_frame,
                                         text='Side C:')
        self.SideC_entry = tkinter.Entry(self.SideC_frame,
                                         width=35)
        self.SideC_label.pack(side='left')
        self.SideC_entry.configure(state = 'readonly')

# Create and pack the widgets for the calculator.
        self.calc_button = tkinter.Button(self.tri_frame,text='Calculate', command=self.calc_ans)
        self.quit_button = tkinter.Button(self.button_frame, text='Exit', command=self.main_window.destroy)
        self.calc_button.pack(side='right')
        self.quit_button.pack(side='right')

      
        # Pack the frames.
        self.SideA_frame.pack()
        self.SideB_frame.pack()
        self.SideC_frame.pack()
        self.tri_frame.pack()
        self.button_frame.pack()

        # Start the main loop.
        tkinter.mainloop()

    def calc_ans(self):
        self.SideA = float(self.SideA_entry.get())
        self.SideB = float(self.SideA_entry.get())
      
        #Calculate the square root of boths sides
        self.SideC_value.set(math.sqrt(self.SideA**2 + self.SideB**2))
      
        return self
  

Pyth_The = Pythagorean()

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