How to customize button ok in Gtk.MessageDialog with CSS?
Question: My day's question is about apply CSS in default button in Gtk.MessageDialog. I
tried a lot things without result.

The deal is to find th good id like buttons, or GTKbutton, or
GtkMessageDialog.Button,......

    
    
     #!/usr/bin/env python
        # -*- coding: ISO-8859-1 -*-
        #demo_messagedialog_css.py
        from gi.repository import Gtk,Gdk
    
    
    class show_message_dlg:
        def __init__(self, message, type_message=Gtk.MessageType.INFO,stock_message=Gtk.STOCK_DIALOG_INFO, decorate=True):
            """
            This Function is used to show an message 
            error dialog when an error occurs.
            error_string - The error string that will be displayed on the dialog.
            ==>type_message=gtk.MESSAGE_ERROR for error message
            ==>type_message=gtk.MESSAGE_INFO for information message
            ==>type_message=gtk.MESSAGE_WARNING for  warning message
            GTK_WIN_POS_NONE
    
    
            GTK_WIN_POS_CENTER equivalent in python to Gtk.WindowPosition.CENTER
            GTK_WIN_POS_MOUSE equivalent in python to Gtk.WindowPosition.MOUSE
            GTK_WIN_POS_CENTER_ALWAYS equivalent in python to Gtk.WindowPosition.CENTER_ALWAYS
            GTK_WIN_POS_CENTER_ON_PARENT equivalent in python to Gtk.WindowPosition.CENTER_ON_PARENT 
            """
            self.message = message
            self.message_dlg = Gtk.MessageDialog(type = type_message
                                    , buttons = Gtk.ButtonsType.OK)
            self.message_dlg.set_decorated(decorate)
            self.message_dlg.set_markup(self.message)
            self.message_dlg.set_position(Gtk.WindowPosition.CENTER_ON_PARENT )
            style_provider = Gtk.CssProvider()
    
            css = """
                GtkMessageDialog
                { background:linear-gradient(to bottom, green, rgba(0,255,0,0));}
                #Buttons{ background-color: yellow}
    
                """
            style_provider.load_from_data(css)
            Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), 
            style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    
        def run(self):
            reponse = self.message_dlg.run()
            self.message_dlg.destroy()      
            return reponse  
    
    
    
    if __name__ == "__main__":
        exemple = show_message_dlg(u"message in the box dialog ")
        exemple.run()
        Gtk.main()
    

after few white night and 150 black coffe I found a small part of answer

    
    
    #!/usr/bin/env python
    # -*- coding: ISO-8859-1 -*-
    #demo_messagedialog_css1.py
    from gi.repository import Gtk,Gdk
    
    class MyButtonClass(Gtk.Button):
        __gtype_name__ = 'MyButton'
        def __init__(self, label):
            Gtk.Button.__init__(self, label)
            self.connect("clicked", self._clicked1)
    
        def _clicked1(self, button):
            print "button ok clicked"
    
    class show_message_dlg:
        def __init__(self, message, type_message=Gtk.MessageType.INFO,stock_message=Gtk.STOCK_DIALOG_INFO, decorate=True):   
            self.message = message
            self.message_dlg = Gtk.MessageDialog(type = type_message)
            self.message_dlg.set_decorated(decorate)
            self.message_dlg.set_markup(self.message)
            self.message_dlg.set_position(Gtk.WindowPosition.CENTER_ALWAYS )
    
            button_v = MyButtonClass('Ok button')
            self.message_dlg.add_action_widget(button_v, Gtk.ResponseType.OK)
            self.message_dlg.set_default_response(Gtk.ResponseType.OK)
            # line below necessary if button not defined like Gtk.MessageDialog(type = type_message, buttons = Gtk.ButtonsType.OK)
            self.message_dlg.show_all() 
            style_provider = Gtk.CssProvider()
    
            css = """
                GtkMessageDialog
                { background:linear-gradient(to bottom, yellow, rgba(0,255,0,0));}
    
                MyButton {
                    color: darkgrey;
                    font: Comic Sans 20;} /* run OK for label font */
    
                MyButton GtkLabel{ background-color: blue} /* run OK for button background label*/
                /*MyButton GtkLabel{ background:linear-gradient(to right, yellow, blue,yellow,green,red,orange);}*/ /* run OK for button background label*/
    
                MyButton:active GtkLabel{ background-color: red;} /* do not run if state change */
    
                """
            style_provider.load_from_data(css)
            Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), 
            style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    
        def run(self):
            reponse = self.message_dlg.run()
            self.message_dlg.destroy()      
            return reponse  
    
    if __name__ == "__main__":
        exemple = show_message_dlg(u"message in the dialog box ")
        response = exemple.run()
        if response == Gtk.ResponseType.OK:
            print("OK button clicked and end")
        else:
            print("destroyed")
        Gtk.main()
    

please note special class button with class atribut **gtype_name** =
'MyButton' and CSS command adressed by MyButton {}

Now I don't understand why part below not OK when I click on button

    
    
    MyButton:active GtkLabel{ background-color: red;} 
    


Answer: ok I found a solution for specific problem button

    
    
    MyButton:active GtkLabel{ background: red;} 
    

my exemple

    
    
    #!/usr/bin/env python
    # -*- coding: ISO-8859-1 -*-
    #demo_messagedialog_css2.py
    from gi.repository import Gtk,Gdk
    
    class MyButtonClass(Gtk.Button):
        __gtype_name__ = 'MyButton'
        def __init__(self, label):
            Gtk.Button.__init__(self, label)
            self.connect("clicked", self._clicked1)
    
        def _clicked1(self, button):
            print "button ok clicked"
    
    class show_message_dlg:
        def __init__(self, message, type_message=Gtk.MessageType.INFO,stock_message=Gtk.STOCK_DIALOG_INFO, decorate=True):   
            self.message = message
            self.message_dlg = Gtk.MessageDialog(type = type_message)
            self.message_dlg.set_decorated(decorate)
            self.message_dlg.set_markup(self.message)
            self.message_dlg.set_position(Gtk.WindowPosition.CENTER_ALWAYS )
    
            button_v = MyButtonClass('Ok button')
            self.message_dlg.add_action_widget(button_v, Gtk.ResponseType.OK)
            self.message_dlg.set_default_response(Gtk.ResponseType.OK)
            # line below necessary if button not defined like Gtk.MessageDialog(type = type_message, buttons = Gtk.ButtonsType.OK)
            self.message_dlg.show_all() 
            style_provider = Gtk.CssProvider()
    
            css = """
                GtkMessageDialog
                { background:linear-gradient(to bottom, yellow, rgba(0,255,0,0));}
                MyButton {
                    color: darkgrey;
                    font: Comic Sans 20;} 
                MyButton:active { background: red;}
                MyButton GtkLabel{ background:linear-gradient(to right, yellow, blue,yellow,green,red,orange);}
                """
            style_provider.load_from_data(css)
            Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), 
            style_provider,     
            Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
    
        def run(self):
            reponse = self.message_dlg.run()
            self.message_dlg.destroy()      
            return reponse  
    
    if __name__ == "__main__":
        exemple = show_message_dlg(u"message in the dialog box ")
        response = exemple.run()
        if response == Gtk.ResponseType.OK:
            print("OK button clicked and end")
        else:
            print("destroyed")
        Gtk.main()
    

