Addon to one click hide for viewport grid

Hi friends is there any addon for onclick disable or enable viewport grid?

Hi man

here a little code , you can run the script and then run the operator in the viewport typing the gridswitch
it should switch the floorgrid on and off

import bpy

class gridswitch(bpy.types.Operator):
    bl_idname = "wm.gridswitch"
    bl_label = "Simple Object Operator"
    def execute(self, context):
        if bpy.context.space_data.overlay.show_floor == True :
            bpy.context.space_data.overlay.show_floor = False
        else:
            bpy.context.space_data.overlay.show_floor = True
        return {'FINISHED'}

def register():
    bpy.utils.register_class(gridswitch)

def unregister():
    bpy.utils.unregister_class(gridswitch)

if __name__ == "__main__":
    register()
    # test call

:star_struck: Thank you.How to enable this in viewport ?,i paste the script and did Text-Run script.

Do you mean , add a button in the viewport?

yes i want a button in viewport.

Hi man,
I know only how add a panel button
take this script and run it , it will add a button in the toolbar

import bpy

# THIS WILL MAKE A PANEL 
class custom_PT_Panel(bpy.types.Panel):
    bl_label = "grid_on_off"
    bl_idname = "grid_PT_custom_panel"
    bl_space_type = "VIEW_3D"   
    bl_region_type = "TOOLS"
    
    def draw(self, context):         
        layout = self.layout #-------------------------- NEW LARGE LAYOUT  declared
        layout.operator("wm.gridswitch",    text=  "GRID " , icon="MESH_GRID" ) 
        # THIS WILL MAKE A BUTTON WITH YOU OPERATOR
        
        
# THIS IS THE OPERATOR 
class gridswitch(bpy.types.Operator):
    bl_idname = "wm.gridswitch"
    bl_label = "Simple floor switcher"
    def execute(self, context):
        if bpy.context.space_data.overlay.show_floor == True :
            bpy.context.space_data.overlay.show_floor = False
        else:
            bpy.context.space_data.overlay.show_floor = True
        return {'FINISHED'}

def register():
    bpy.utils.register_class(gridswitch)
    bpy.utils.register_class(custom_PT_Panel)

def unregister():
    bpy.utils.unregister_class(gridswitch)
    bpy.utils.unregister_class(custom_PT_Panel)
if __name__ == "__main__":
    register()
    # test call

Thankyou Fenix