def _add_widget( self, wtype, *args, **kw ) :
        """internal routine to capture details of widget to add to menu."""

        # we never add widgets when the menu is posted
        if self.is_posted :
            return -1

        wdict = {}
        wdict[ 'type' ] = wtype
        self._button_no += 1
        wdict[ 'widget_id' ] =  self._button_no

        # process any options applicable to us rather than the widget
        # we remove these from the keywords dictionary, because we'll
        # be using the remaining keywords when we create the widget

        insert_before = kw.pop( 'insert_before', None )
        wdict[ 'auto_post' ] = kw.pop( 'auto_post', False)
        wdict[ 'sub_menu' ] = kw.pop( 'sub_menu', None )
        wdict[ 'pre_pack_command' ] = kw.pop( 'pre_pack_command', None )
        wclass = kw.pop( 'widget_object', None )

        # save the keywords and positional arguments
        wdict[ 'args'] = args
        wdict[ 'kw' ] = kw

        if  wtype != 'widget' :
            # refuse to mix random widgets with normal menu components
            if len( self._wdicts ) > 0 and \
                   self._wdicts[ 0 ][ 'type' ] == 'widget' :
                return -1
        else :
            if len( self._wdicts ) != 0 :
                return -1

            if wclass is None :
                return -1

            wdict[ 'widget_object' ] = wclass

        # add to list of widgets in the appropriate place
        if insert_before is None:
            self._wdicts.append( wdict )
        else :
            for i in range( len( self._wdicts ) ) :
                if self._wdicts[ i ][ 'widget_id' ] == insert_before :
                    self._wdicts = self._wdicts[ : i ] + [ wdict ] + \
                                  self._wdicts[ i : ]
                    return self._button_no

            self._wdicts.append( wdict )

        return self._button_no
internal routine to capture details of widget to add to menu.
recipes/Python/442500_ExtraMenu__TkInter_menu_arbitrary_widgets/recipe-442500.py