0

I want to clear the output result of the equation. But when I press the clear button it gives an error

"NameError: name 'CalculationOutput' is not defined"

How do I solve this problem.

import tkinter as tk

compression = ""

GuiRoot = tk.Tk()

MainCanvas = tk.Canvas(GuiRoot, width=500, height=400, relief="raised")
MainCanvas.pack()

DesignText1 = tk.Label(GuiRoot, text="Calculate the Square Root")
DesignText1.config(font=("halvetica", 14))
MainCanvas.create_window(250, 25, window=DesignText1)

DesignText2 = tk.Label(GuiRoot, text="Type your number")
DesignText2.config(font=("halvetica", 10))
MainCanvas.create_window(250, 100, window=DesignText2)

UserEntryBox = tk.Entry(GuiRoot)
MainCanvas.create_window(250, 200, window=UserEntryBox)

def GetSquareRoot():
    x = UserEntryBox.get()

    DesignText3 = tk.Label(GuiRoot, text="The Square Root of " + x + ' is:', font=("halvetica", 10))
    MainCanvas.create_window(250, 260, window=DesignText3)

    CalculationOutput = tk.Label(GuiRoot, text=float(x)**0.5, font=("halvetica", 10, "bold"))
    MainCanvas.create_window(250, 280, window=CalculationOutput)

CalculationButton = tk.Button(text="Get the Square Root", command=GetSquareRoot, bg="brown", fg='white', font=('halvetica', 9, 'bold'))
MainCanvas.create_window(250, 230, window=CalculationButton)


def ClearButtonFunc():
    global compression
    compression = ""
    CalculationOutput.set("")

ClearButton = tk.Button(GuiRoot, text="Clear Text", command=ClearButtonFunc)
MainCanvas.create_window(250, 320, window=ClearButton)


GuiRoot.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685

0 Answers0