Search code examples
pythongtk3

Python GTK+ 3: How to make a button circular?


so basically I want to take a Gtk.Button, which is by default a rectangle, and turn it into a circle. According to https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Button.html you can do this by adding the .circular class. However, I'm not quite sure what is meant by this, or how to do it. Is it something that I need to add to my CSS file? Thanks.


Solution

  • You Can make a button circular using Css :-

        button{
              background-image: none;
              border-radius: 40px;
              padding: 30px 0px;
         }
    

    You just have to modify the values for your button size ...

    Adding the style class work only with a few themes.To do that you have to

    gtk_style_context_add_class(
        gtk_widget_get_style_context( GTK_WIDGET(button) ),
        "circular"
    );
    

    add the style context Making a GtkButton round