How to create custom widget?

I want to create custom widget but i confuse where to begin. Anyone know the basic step to do this? thanks