# ==============================================================================
"""MESSAGE : demo program for simple callback functions"""
# ==============================================================================
__author__  = "Christophe Schlick"
__version__ = "2.0" # use the same generic callback function for all widgets
__date__    = "2021-03-15"
# ==============================================================================
from ezTK import *
# ------------------------------------------------------------------------------
def main():
  """create the main window and pack the widgets"""
  global win
  font1, font2 = 'Arial 14', 'Arial 18 bold'
  win = Win(title='MESSAGE', font=font2, op=5, grow=False)
  # ----------------------------------------------------------------------------
  text, fg, bg = 'Try to find the correct button', '#FFF', '#00F'
  Label(win, text=text, fg=fg, bg=bg, width=25, height=2, border=2) 
  # ----------------------------------------------------------------------------
  frame = Frame(win, font=font1)
  Button(frame, text='AAA', command=lambda: on_button(0)) # index = 0
  Button(frame, text='BBB', command=lambda: on_button(1)) # index = 1
  Button(frame, text='CCC', command=lambda: on_button(2)) # index = 2
  # ----------------------------------------------------------------------------
  win.label = win[0] # set friendly names for all widgets used in callbacks
  win.loop()
# ------------------------------------------------------------------------------
def on_button(index):
  """generic callback function for all three buttons"""
  win.label['text'] = ('RETRY','YOU WIN !','GAME OVER')[index]
  win.label['fg'] = ('#FFF','#000','#FFF')[index]
  win.label['bg'] = ('#F70','#0F0','#F00')[index]  
# ==============================================================================
if __name__ == '__main__':
  main()
# ==============================================================================
