I am trying to make a simple GUI in UI that will give me the hypotenuse from 2 numbers A and B. the button was displayed, but went away(not sure why). I can write numbers in the upper 2 text field’s and I’d like the button to perform a hypotenuse calc on the numbers and display it in 3rd field, which for some reason I believe needs to be a label and not TextField. Any help is appreciated. Thanks!
————————————————————————————————————————————————————————
import ui
import math
import string
view = ui.View()
view.name = 'hypotenuse'
view.background_color = 'white'
# variables for lengths A and B
A = float()
B = float()
# label for length
LenLbl = ui.Label()
LenLbl.text = 'Length'
LenLbl.x = 370
LenLbl.y = 80
# text feild input for length (A)
Length = ui.TextField(A)
Length.x = 300
Length.y = 150
Length.width = 200
Length.border_width = 1
# label for width
widLbl = ui.Label()
widLbl.text = 'Width'
widLbl.x = 370
widLbl.y = 280
# text feild input for width (B)
Width = ui.TextField(B)
Width.x = 300
Width.y = 350
Width.width = 200
Width.border_width = 1
# label for result
resLbl = ui.Label()
resLbl.text = 'Result'
resLbl.x = 370
resLbl.y = 480
# label that should show result of hypotenuse of A and B when button is pushed
Result = ui.Label()
Result.text = str()
Result.x = 300
Result.y = 550
Result.width = 200
Result.border_width = 1
# math for hypot calc
C = math.hypot(A, B)
# attempt at getting button to perform calc and put result in result Label
def button_tapped(C):
Result.text = float(eval(C))
button = ui.Button()
button.text = ' Calculate '
button.x = 300
button.y = 650
button.action = button_tapped
button.border_width = 1
# putting items on screen in GUI(only button wont show up)
view.add_subview(Width)
view.add_subview(widLbl)
view.add_subview(Length)
view.add_subview(LenLbl)
view.add_subview(button)
view.add_subview(resLbl)
view.add_subview(Result)
view.present('fullscreen')