A widget that creates a signal when clicked on
Class GtkButton
The GtkButton widget is generally used to attach a function to that is called when the button is pressed. The various signals and how to use them are outlined below.
The GtkButton widget can hold any valid child widget. That is it can hold most any other standard GtkWidget. The most commonly used child is the GtkLabel.
Methods | |
clicked | Emits a "clicked" signal to the given GtkButton. |
enter | Emits a "enter" signal to the given GtkButton. |
get_alignment | Gets the alignment of the child in the button. |
get_focus_on_click | Returns whether the button grabs focus when it is clicked with the mouse. |
get_image | Gets the widget that is currenty set as the image of button. |
get_image_position | Gets the position of the image relative to the text inside the button. |
get_label | Fetches the text from the label of the button. |
get_relief | Returns the current relief style of the given GtkButton. |
get_use_stock | Returns whether the button label is a stock item. |
get_use_underline | Returns whether an embedded underline in the button label indicates a mnemonic. |
leave | Emits a "leave" signal to the given GtkButton. |
new_from_stock | Creates a new GtkButton containing the image and text from a stock item. |
new_with_label | Creates a GtkButton widget with a GtkLabel child containing the given text. |
new_with_mnemonic | Creates a new GtkButton containing a label. |
pressed | Emits a "pressed" signal to the given GtkButton. |
released | Emits a "released" signal to the given GtkButton. |
set_alignment | Sets the alignment of the child. |
set_focus_on_click | Sets whether the button will grab focus when it is clicked with the mouse. |
set_image | Set the image of button to the given widget. |
set_image_position | Sets the position of the image relative to the text inside the button. |
set_label | Sets the text of the label of the button. |
set_relief | Sets the relief style of the edges of the given GtkButton widget. |
set_use_stock | Use a stock id. |
set_use_underline | Sets an underline. |
signal_activate | The activate signal on GtkButton is an action signal and emitting it causes the button to animate press then release. |
signal_clicked | Emitted when the button has been activated (pressed and released). |
signal_enter | Emitted when the pointer enters the button. |
signal_leave | Emitted when the pointer leaves the button. |
signal_pressed | Emitted when the button is pressed. |
signal_released | Emitted when the button is released. |
Emits a "clicked" signal to the given GtkButton.
GtkButton.clicked()
Emits a "enter" signal to the given GtkButton.
GtkButton.enter()
Gets the alignment of the child in the button.
GtkButton.get_alignment()
Return | an array [ horizontal alignment, vertical alignment ] |
Returns whether the button grabs focus when it is clicked with the mouse.
GtkButton.get_focus_on_click()
Return | TRUE if the button grabs focus when it is clicked with the mouse. |
Gets the widget that is currenty set as the image of button.
GtkButton.get_image()
Return | a GtkWidget or nil in case there is no image |
This may have been explicitly set by gtk_button_set_image() or constructed by gtk_button_new_from_stock().
Gets the position of the image relative to the text inside the button.
GtkButton.get_image_position()
Return | the position (GtkPositionType). |
Fetches the text from the label of the button.
GtkButton.get_label()
Return | The text of the label widget, or nil. |
If the label text has not been set the return value will be NULL. This will be the case if you create an empty button with gtk_button_new() to use as a container.
Returns the current relief style of the given GtkButton.
GtkButton.get_relief()
Return | The current GtkReliefStyle. |
Returns whether the button label is a stock item.
GtkButton.get_use_stock()
Return | TRUE if the button label is used to select a stock item instead of being used directly as the label text. |
Returns whether an embedded underline in the button label indicates a mnemonic.
GtkButton.get_use_underline()
Return | TRUE if an embedded underline in the button label indicates the mnemonic accelerator keys. |
Emits a "leave" signal to the given GtkButton.
GtkButton.leave()
Creates a new GtkButton containing the image and text from a stock item.
GtkButton.new_from_stock( stock_id )
stock_id | the name of the stock item |
Return | a new GtkButton |
Some stock ids have preprocessor macros like GTK_STOCK_OK and GTK_STOCK_APPLY.
If stock_id is unknown, then it will be treated as a mnemonic label (as for gtk_button_new_with_mnemonic()).
Creates a GtkButton widget with a GtkLabel child containing the given text.
GtkButton.new_with_label( label )
label | The text you want the GtkLabel to hold. |
Return | The newly created GtkButton widget. |
Creates a new GtkButton containing a label.
GtkButton.new_with_mnemonic( label )
label | The text of the button, with an underscore in front of the mnemonic character |
Return | a new GtkButton |
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.
Emits a "pressed" signal to the given GtkButton.
GtkButton.pressed()
Emits a "released" signal to the given GtkButton.
GtkButton.released()
Sets the alignment of the child.
GtkButton.set_alignment( xalign, yalign )
xalign | the horizontal position of the child, 0.0 is left aligned, 1.0 is right aligned |
yalign | the vertical position of the child, 0.0 is top aligned, 1.0 is bottom aligned |
This property has no effect unless the child is a GtkMisc or a GtkAligment.
Sets whether the button will grab focus when it is clicked with the mouse.
GtkButton.set_focus_on_click( focus_on_click )
focus_on_click | whether the button grabs focus when 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.
Set the image of button to the given widget.
GtkButton.set_image( image )
image | a widget to set as the image for the button. |
Note that it depends on the "gtk-button-images" setting whether the image will be displayed or not, you don't have to call gtk_widget_show() on image yourself.
Sets the position of the image relative to the text inside the button.
GtkButton.set_image_position( position )
position | the position (GtkPositionType). |
Sets the text of the label of the button.
GtkButton.set_label( label )
label | a string |
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.
Sets the relief style of the edges of the given GtkButton widget.
GtkButton.set_relief( newstyle )
newstyle | The new GtkReliefStyle. |
Three styles exist, GTK_RELIEF_NORMAL, GTK_RELIEF_HALF, GTK_RELIEF_NONE. The default style is, as one can guess, GTK_RELIEF_NORMAL.
Use a stock id.
GtkButton.set_use_stock( use_stock )
use_stock | TRUE if the button should use a stock item |
If true, the label set on the button is used as a stock id to select the stock item for the button.
Sets an underline.
GtkButton.set_use_underline( use_underline )
use_underline | TRUE if underlines in the text indicate mnemonics |
If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.
The activate signal on GtkButton is an action signal and emitting it causes the button to animate press then release.
GtkButton.signal_activate()
Applications should never connect to this signal, but use the "clicked" signal.
Emitted when the button has been activated (pressed and released).
GtkButton.signal_clicked()
Emitted when the pointer enters the button.
GtkButton.signal_enter()
GtkButton::enter has been deprecated since version 2.8 and should not be used in newly-written code. Use the "enter-notify-event" signal.
Emitted when the pointer leaves the button.
GtkButton.signal_leave()
GtkButton::leave has been deprecated since version 2.8 and should not be used in newly-written code. Use the Widget "leave-notify-event" signal.
Emitted when the button is pressed.
GtkButton.signal_pressed()
GtkButton::pressed has been deprecated since version 2.8 and should not be used in newly-written code. Use the Widget "button-press-event" signal.
Emitted when the button is released.
GtkButton.signal_released()
GtkButton::released has been deprecated since version 2.8 and should not be used in newly-written code. Use the Widget "button-release-event" signal.