2

I've read GTK3 Python document and its Button part.

Well I'm trying to make a Button like this (It's Klavaro software): enter image description here

but I didn't find anything about special settings of Button.

So how to create a Button in GTK3 Python like mentioned picture?

1
  • @JacobVlijm Yes, I've removed that. Thanks for your mentioned.
    – mortymacs
    Jan 16, 2017 at 9:25

1 Answer 1

2

A GtkButton derives from a GtkContainer so it can contain any other widget actually. Just use the add() method to add a GtkBox widget for the layout and labels and an icon inside that.

Here's a very quick recreation in Glade, if you can't figure it out with pure Python code I'll give you an example when I have some more time.

enter image description here

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.1 -->
<interface>
  <requires lib="gtk+" version="3.10"/>
  <object class="GtkButton" id="button1">
    <property name="visible">True</property>
    <property name="can_focus">True</property>
    <property name="receives_default">True</property>
    <child>
      <object class="GtkBox" id="box1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="spacing">8</property>
        <child>
          <object class="GtkImage" id="image1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="icon_name">gtk-dialog-error</property>
            <property name="icon_size">6</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkBox" id="box2">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <property name="valign">center</property>
            <property name="orientation">vertical</property>
            <property name="spacing">4</property>
            <child>
              <object class="GtkLabel" id="label1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="xalign">0</property>
                <property name="label" translatable="yes">0 - Introduction</property>
                <attributes>
                  <attribute name="weight" value="bold"/>
                </attributes>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkLabel" id="label2">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="xalign">0</property>
                <property name="label" translatable="yes">Learn how to type correctly</property>
                <property name="ellipsize">start</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">True</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="fill">True</property>
            <property name="position">1</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>
1
  • Thank you so much. I didn't know that I can add items (e.g. HBox) inside of Button. I've implemented the Python code.
    – mortymacs
    Jan 16, 2017 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .