how to put functions inside of widgets

there are a few way to run a function in widgets:

option 1 – ShortCodes

You can create a custom shortcode and run that function by entering the shortcode into a simple text widget:

//this is to make sure WordPress renders the shortcodes in a text widget
add_filter('widget_text', 'do_shortcode');

add_shortcode('my_short_code','my_function');

function my_function(){
  //do whatever you want
}

and then simply add [my_short_code] to any text widget to run your function.

Option 2 Plugins

You can use one of the many plugins out there that let you run php in a widget like:

Option 3 Custom Widgets

The last way is to write your own widget using the very simple Widgets API