I would like to get the button title of my script to decide with math operation do. But I have problem with parameter, data gotten from sender (str, int).
I check an answer given to newbie (I did not remember exactly the user) an adapt it, but is not working properly. Here is the code.
Is a simply math app for my kids. In developing of course.
Thanks
import ui
#import console
texto1 = ''
mains=ui.View(frame=(10,10,10,10), background_color='#008000', name='Math for Fun')
mains.present('view')
controls1=ui.View(frame=(0,0,410,200), background_color='#e6ec5f', name='controls1')
def button_tapped(sender):
#if button_tapped == b_top1.title('SUM'):
#itexto1 = 'Hello World'
texto1 = sender.title
#else:
#texto1 = str(300)
return texto1
b_top1 = ui.Button()
b_top1.frame = (20,80,80,50)
b_top1.title = 'SUM'
b_top1.font = ('<System-Bold>', 20)
b_top1.background_color = ('#07b2cc')
b_top1.border_width = 2
b_top1.corner_radius = 5
b_top1.action = button_tapped
b_top2 = ui.Button()
b_top2.frame = (115,80,80,50)
b_top2.title = 'SUBS'
b_top2.font = ('<System-Bold>', 20)
b_top2.background_color = '#ff8909'
b_top2.border_width = 2
b_top2.corner_radius = 5
b_top1.action = button_tapped
b_top3 = ui.Button()
b_top3.frame = (215,80,80,50)
b_top3.title = 'MULT'
b_top3.font = ('<System-Bold>', 20)
b_top3.background_color = '#07de1a'
b_top3.border_width = 2
b_top3.corner_radius = 5
b_top1.action = button_tapped
b_top4 = ui.Button()
b_top4.frame = (310,80,80,50)
b_top4.title = 'DIV'
b_top4.font = ('<System-Bold>', 20)
b_top4.background_color = '#ffd12b'
b_top4.border_width = 2
b_top4.corner_radius = 5
b_top1.action = button_tapped
lb1 = ui.Label(name = 'Label1', bg_color = 'yellow', frame =(80,20,250,50))
lb1.border_color = 'black'
lb1.border_width = 1
lb1.flex = 'RB'
lb1.alignment=1
lb1.text = 'VAMOS A JUGAR MATEMATICAS'
txt_field1 = ui.TextField()
txt_field1.frame = (150,145,100,50)
txt_field1.border = (50,20,50,50)
txt_field1.bg_color = (.9, .98, 1.0)
txt_field1.text = button_tapped()
mains.add_subview(controls1)
controls1.add_subview(b_top1)
controls1.add_subview(b_top2)
controls1.add_subview(b_top3)
controls1.add_subview(b_top4)
controls1.add_subview(lb1)
controls1.add_subview(txt_field1)