Gtk.Button¶
Example¶
Methods¶
- Inherited:
Gtk.Bin (1), Gtk.Container (35), Gtk.Widget (278), GObject.Object (37), Gtk.Buildable (10), Gtk.Actionable (5), Gtk.Activatable (6)
- Structs:
Gtk.ContainerClass (5), Gtk.WidgetClass (12), GObject.ObjectClass (5)
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Gtk.Container (10), Gtk.Widget (82), GObject.Object (7), Gtk.Buildable (10), Gtk.Actionable (4), Gtk.Activatable (2)
|
|
|
|
|
|
|
|
|
|
|
Properties¶
Name |
Type |
Flags |
Short Description |
|---|---|---|---|
r/w/c/en |
Whether the image will always be shown |
||
r/w/en |
Child widget to appear next to the button text |
||
r/w/en |
The position of the image relative to the text |
||
r/w/c/en |
Text of the label widget inside the button, if the button contains a label widget |
||
r/w/en |
The border relief style |
||
d/r/w/c/en |
If set, the label is used to pick a stock item instead of being displayed |
||
r/w/c/en |
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key |
||
d/r/w/en |
Horizontal position of child in available space. 0.0 is left aligned, 1.0 is right aligned |
||
d/r/w/en |
Vertical position of child in available space. 0.0 is top aligned, 1.0 is bottom aligned |
Style Properties¶
- Inherited:
Name |
Type |
Default |
Flags |
Short Description |
|---|---|---|---|---|
|
|
d/r |
How far in the x direction to move the child when the button is depressed |
|
|
|
d/r |
How far in the y direction to move the child when the button is depressed |
|
|
d/r |
Extra space to add for GTK_CAN_DEFAULT buttons |
||
|
d/r |
Extra space to add for GTK_CAN_DEFAULT buttons that is always drawn outside the border |
||
|
d/r |
Whether the child_displacement_x/_y properties should also affect the focus rectangle |
||
|
|
d/r |
Spacing in pixels between the image and label |
|
|
d/r |
Border between button edges and child. |
Signals¶
- Inherited:
Name |
Short Description |
|---|---|
The |
|
Emitted when the button has been activated (pressed and released). |
|
Emitted when the pointer enters the button. |
|
Emitted when the pointer leaves the button. |
|
Emitted when the button is pressed. |
|
Emitted when the button is released. |
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
|---|---|---|---|
bin |
r |
Class Details¶
- class Gtk.Button(*args, **kwargs)¶
- Bases:
- Abstract:
No
- Structure:
The
Gtk.Buttonwidget is generally used to trigger a callback function that is called when the button is pressed. The various signals and how to use them are outlined below.The
Gtk.Buttonwidget can hold any valid child widget. That is, it can hold almost any other standardGtk.Widget. The most commonly used child is theGtk.Label.- CSS nodes
Gtk.Buttonhas a single CSS node with name button. The node will get the style classes .image-button or .text-button, if the content is just an image or label, respectively. It may also receive the .flat style class.Other style classes that are commonly used with
Gtk.Buttoninclude .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.Button-like widgets like
Gtk.ToggleButton,Gtk.MenuButton,Gtk.VolumeButton,Gtk.LockButton,Gtk.ColorButton,Gtk.FontButtonorGtk.FileChooserButtonuse style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file to differentiate themselves from a plainGtk.Button.- classmethod new()[source]¶
- Returns:
The newly created
Gtk.Buttonwidget.- Return type:
Creates a new
Gtk.Buttonwidget. To add a child widget to the button, useGtk.Container.add().
- classmethod new_from_icon_name(icon_name, size)[source]¶
- Parameters:
size (
int) – an icon size (Gtk.IconSize)
- Returns:
a new
Gtk.Buttondisplaying the themed icon- Return type:
Creates a new button containing an icon from the current icon theme.
If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
This function is a convenience wrapper around
Gtk.Button.new() andGtk.Button.set_image().New in version 3.10.
- classmethod new_from_stock(stock_id)[source]¶
- Parameters:
stock_id (
str) – the name of the stock item- Returns:
a new
Gtk.Button- Return type:
Creates a new
Gtk.Buttoncontaining the image and text from a ‘stock item [gtkstock]’. Some stock ids have preprocessor macros likeGtk.STOCK_OKandGtk.STOCK_APPLY.If stock_id is unknown, then it will be treated as a mnemonic label (as for
Gtk.Button.new_with_mnemonic()).Deprecated since version 3.10: Stock items are deprecated. Use
Gtk.Button.new_with_label() instead.
- classmethod new_with_label(label)[source]¶
- Parameters:
- Returns:
The newly created
Gtk.Buttonwidget.- Return type:
Creates a
Gtk.Buttonwidget with aGtk.Labelchild containing the given text.
- classmethod new_with_mnemonic(label)[source]¶
- Parameters:
label (
str) – The text of the button, with an underscore in front of the mnemonic character- Returns:
a new
Gtk.Button- Return type:
Creates a new
Gtk.Buttoncontaining a label. If characters in label are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use “__” (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic. Pressing Alt and that key activates the button.
- clicked()[source]¶
Emits a
Gtk.Button::clickedsignal to the givenGtk.Button.
- enter()[source]¶
Emits a
Gtk.Button::entersignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::enter-notify-eventsignal.
- get_alignment()[source]¶
- Returns:
- xalign:
return location for horizontal alignment
- yalign:
return location for vertical alignment
- Return type:
Gets the alignment of the child in the button.
New in version 2.4.
Deprecated since version 3.14: Access the child widget directly if you need to control its alignment.
- get_always_show_image()[source]¶
-
Returns whether the button will ignore the
Gtk.Settings:gtk-button-imagessetting and always show the image, if available.New in version 3.6.
- get_event_window()[source]¶
- Returns:
self’s event window.
- Return type:
Returns the button’s event window if it is realized,
Noneotherwise. This function should be rarely needed.New in version 2.22.
- get_focus_on_click()[source]¶
-
Returns whether the button grabs focus when it is clicked with the mouse. See
Gtk.Button.set_focus_on_click().New in version 2.4.
Deprecated since version 3.20: Use
Gtk.Widget.get_focus_on_click() instead
- get_image()[source]¶
- Returns:
a
Gtk.WidgetorNonein case there is no image- Return type:
Gtk.WidgetorNone
Gets the widget that is currenty set as the image of self. This may have been explicitly set by
Gtk.Button.set_image() or constructed byGtk.Button.new_from_stock().New in version 2.6.
- get_image_position()[source]¶
- Returns:
the position
- Return type:
Gets the position of the image relative to the text inside the button.
New in version 2.10.
- get_label()[source]¶
- Returns:
The text of the label widget. This string is owned by the widget and must not be modified or freed.
- Return type:
Fetches the text from the label of the button, as set by
Gtk.Button.set_label(). If the label text has not been set the return value will beNone. This will be the case if you create an empty button withGtk.Button.new() to use as a container.
- get_relief()[source]¶
- Returns:
The current
Gtk.ReliefStyle- Return type:
Returns the current relief style of the given
Gtk.Button.
- get_use_stock()[source]¶
- Returns:
Trueif the button label is used to select a stock item instead of being used directly as the label text.- Return type:
Returns whether the button label is a stock item.
Deprecated since version 3.10.
- get_use_underline()[source]¶
- Returns:
Trueif an embedded underline in the button label indicates the mnemonic accelerator keys.- Return type:
Returns whether an embedded underline in the button label indicates a mnemonic. See
Gtk.Button.set_use_underline().
- leave()[source]¶
Emits a
Gtk.Button::leavesignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::leave-notify-eventsignal.
- pressed()[source]¶
Emits a
Gtk.Button::pressedsignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::button-press-eventsignal.
- released()[source]¶
Emits a
Gtk.Button::releasedsignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::button-release-eventsignal.
- set_alignment(xalign, yalign)[source]¶
- Parameters:
Sets the alignment of the child. This property has no effect unless the child is a
Gtk.Miscor aGtk.Alignment.New in version 2.4.
Deprecated since version 3.14: Access the child widget directly if you need to control its alignment.
- set_always_show_image(always_show)[source]¶
-
If
True, the button will ignore theGtk.Settings:gtk-button-imagessetting and always show the image, if available.Use this property if the button would be useless or hard to use without the image.
New in version 3.6.
- set_focus_on_click(focus_on_click)[source]¶
- Parameters:
focus_on_click (
bool) – whether the button grabs focus when clicked with the mouse
Sets whether the button will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application.
New in version 2.4.
Deprecated since version 3.20: Use
Gtk.Widget.set_focus_on_click() instead
- set_image(image)[source]¶
- Parameters:
image (
Gtk.WidgetorNone) – a widget to set as the image for the button, orNoneto unset
Set the image of self to the given widget. The image will be displayed if the label text is
Noneor ifGtk.Button:always-show-imageisTrue. You don’t have to callGtk.Widget.show() on image yourself.New in version 2.6.
- set_image_position(position)[source]¶
- Parameters:
position (
Gtk.PositionType) – the position
Sets the position of the image relative to the text inside the button.
New in version 2.10.
- set_label(label)[source]¶
- Parameters:
label (
str) – a string
Sets the text of the label of the button to str. This text is also used to select the stock item if
Gtk.Button.set_use_stock() is used.This will also clear any previously set labels.
- set_relief(relief)[source]¶
- Parameters:
relief (
Gtk.ReliefStyle) – TheGtk.ReliefStyleas described above
Sets the relief style of the edges of the given
Gtk.Buttonwidget. Two styles exist,Gtk.ReliefStyle.NORMALandGtk.ReliefStyle.NONE. The default style is, as one can guess,Gtk.ReliefStyle.NORMAL. The deprecated valueGtk.ReliefStyle.HALFbehaves the same asGtk.ReliefStyle.NORMAL.
- set_use_stock(use_stock)[source]¶
-
If
True, the label set on the button is used as a stock id to select the stock item for the button.Deprecated since version 3.10.
- set_use_underline(use_underline)[source]¶
-
If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.
- do_activate() virtual¶
Signal that causes the button to animate press then release. Applications should never connect to this signal, but use the clicked signal.
- do_clicked() virtual¶
Emits a
Gtk.Button::clickedsignal to the givenGtk.Button.
- do_enter() virtual¶
Emits a
Gtk.Button::entersignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::enter-notify-eventsignal.
- do_leave() virtual¶
Emits a
Gtk.Button::leavesignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::leave-notify-eventsignal.
- do_pressed() virtual¶
Emits a
Gtk.Button::pressedsignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::button-press-eventsignal.
- do_released() virtual¶
Emits a
Gtk.Button::releasedsignal to the givenGtk.Button.Deprecated since version 2.20: Use the
Gtk.Widget::button-release-eventsignal.
Signal Details¶
- Gtk.Button.signals.activate(button)¶
- Signal Name:
activate- Flags:
- Parameters:
button (
Gtk.Button) – The object which received the signal
The
::activatesignal onGtk.Buttonis an action signal and emitting it causes the button to animate press then release. Applications should never connect to this signal, but use theGtk.Button::clickedsignal.
- Gtk.Button.signals.clicked(button)¶
- Signal Name:
clicked- Flags:
- Parameters:
button (
Gtk.Button) – The object which received the signal
Emitted when the button has been activated (pressed and released).
- Gtk.Button.signals.enter(button)¶
- Signal Name:
enter- Flags:
- Parameters:
button (
Gtk.Button) – The object which received the signal
Emitted when the pointer enters the button.
Deprecated since version 2.8: Use the
Gtk.Widget::enter-notify-eventsignal.
- Gtk.Button.signals.leave(button)¶
- Signal Name:
leave- Flags:
- Parameters:
button (
Gtk.Button) – The object which received the signal
Emitted when the pointer leaves the button.
Deprecated since version 2.8: Use the
Gtk.Widget::leave-notify-eventsignal.
- Gtk.Button.signals.pressed(button)¶
- Signal Name:
pressed- Flags:
- Parameters:
button (
Gtk.Button) – The object which received the signal
Emitted when the button is pressed.
Deprecated since version 2.8: Use the
Gtk.Widget::button-press-eventsignal.
- Gtk.Button.signals.released(button)¶
- Signal Name:
released- Flags:
- Parameters:
button (
Gtk.Button) – The object which received the signal
Emitted when the button is released.
Deprecated since version 2.8: Use the
Gtk.Widget::button-release-eventsignal.
Property Details¶
- Gtk.Button.props.always_show_image¶
- Name:
always-show-image- Type:
- Default Value:
- Flags:
If
True, the button will ignore theGtk.Settings:gtk-button-imagessetting and always show the image, if available.Use this property if the button would be useless or hard to use without the image.
New in version 3.6.
- Gtk.Button.props.image¶
- Name:
image- Type:
- Default Value:
- Flags:
The child widget to appear next to the button text.
New in version 2.6.
- Gtk.Button.props.image_position¶
- Name:
image-position- Type:
- Default Value:
- Flags:
The position of the image relative to the text inside the button.
New in version 2.10.
- Gtk.Button.props.label¶
-
Text of the label widget inside the button, if the button contains a label widget
- Gtk.Button.props.relief¶
- Name:
relief- Type:
- Default Value:
- Flags:
The border relief style
- Gtk.Button.props.use_stock¶
- Name:
use-stock- Type:
- Default Value:
- Flags:
If set, the label is used to pick a stock item instead of being displayed
Deprecated since version 3.10.
- Gtk.Button.props.use_underline¶
- Name:
use-underline- Type:
- Default Value:
- Flags:
If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key
- Gtk.Button.props.xalign¶
- Name:
xalign- Type:
- Default Value:
0.5- Flags:
If the child of the button is a
Gtk.MiscorGtk.Alignment, this property can be used to control its horizontal alignment. 0.0 is left aligned, 1.0 is right aligned.New in version 2.4.
Deprecated since version 3.14: Access the child widget directly if you need to control its alignment.
- Gtk.Button.props.yalign¶
- Name:
yalign- Type:
- Default Value:
0.5- Flags:
If the child of the button is a
Gtk.MiscorGtk.Alignment, this property can be used to control its vertical alignment. 0.0 is top aligned, 1.0 is bottom aligned.New in version 2.4.
Deprecated since version 3.14: Access the child widget directly if you need to control its alignment.