Skip to end of metadata
Go to start of metadata

This is a sub-class of Widget

The functions and fields of the widget class are also available for the button class. For instance you can change the theme of a button to the most fancy colors you like.


mgf.createButton( label [, font] )

labelStringThe text displayed on the button
fontFontThe font of the label of the button
Contructor example
button = mgf.createButton( "The Label" )

another_button = mgf.createButton( "Another Label", mgf.FontSmall )


labelStringThe label of the buttonRead / Write
fontFontThe font of the label of the buttonWrite Only


Button does not support any additional functions.


Button Clicked0Called when a user pressed the button via touchscreen or center key.


Example: Button action listener
button = mgf.createButton( "Press me" )

function button.actionListener()
  print( "Button Pressed." )

mgf.setWidget( button, 10, 10, 220, 60 )



Example: 3 buttons
-- Create 3 buttons
small = mgf.createButton( "Small", mgf.FontSmall )		-- A small one
normal = mgf.createButton( "Normal" )					-- A normal one
big = mgf.createButton( "Big", mgf.FontBig )			-- A big one
-- Execute this function when pressing the small button
small.actionListener = function()
	print("Small button pressed")  
-- Create a function that will be called by pressing the normal button
function normalActionListener()
  	print("Normal button pressed") 
  	-- Change label of the normal button
  	normal.label = "Standard"
-- Create a function that will be called by pressing the big button
function bigActionListener( widget, action )
  	print("Big button pressed")
  	-- This function includes the widget
  	print("Widget: ", widget.label )
  	-- Kind of action detected by the widget (for a button this is always 0)
    print("Action: ", action )
-- Set the action listeners of the functions that will be called when pressing the buttons
normal.actionListener = normalActionListener				
big.actionListener = bigActionListener	
-- Create a panel and add the buttons 
panel = mgf.createPanel()
panel:addWidget( small, 102, 25, 36, 20 )
panel:addWidget( normal, 70, 75, 100, 40 )
panel:addWidget( big, 45, 150, 150, 150 )
mgf.setWidget( panel )

Common mistakes

  • Make sure you've created the function before assigning it to an actionListener.
  • Don't include the Parentheses of the function when assigning it to an actionListener.



  • No labels