English 中文(简体)
PyGTK - Button Class
  • 时间:2024-12-22

PyGTK - Button Class


Previous Page Next Page  

The gtk.Button widget is usually displayed as a pushbutton with a text label. It is generally used to attach a callback function or method that is called when the button is cpcked.

The gtk.Button class has the following constructor −

gtk.Button(label = None, stock = None, use_underpne = True)

Wherein,

    Label − The text to be displayed by the button label

    Stock − The stock id identifying the stock image and text to be used in the button. Default is None.

    Underpne − If True, an underscore in the text indicates the next character should be underpned and used for the mnemonic accelerator.

Some of the predefined constants for stock parameter are −

    STOCK_OK

    STOCK_STOP

    STOCK_YES

    STOCK_NO

    STOCK_QUIT

    STOCK_CANCEL

    STOCK_CLOSE

The Button class has the following important methods −

S.NO Methods and Description
1

set_label()

This sets the text of the button label to label. This string is also used to select the stock item if the "use_stock" property is True.

2

get_label()

This retrieves the text from the label of the button

3

set_focus_on_cpck()

If True, the button grabs focus when cpcked with the mouse.

4

set_apgnment()

This is the horizontal and vertical apgnment of the child widget. The value ranges from 0.0 to 1.0.

5

set_image()

This sets the image property to the value of image. The "gtkbutton-images" property should be set to True.

The following signals are emitted by the Button widget −

activate This is emitted when the gtk.Widget s activate() method is called. For a button it causes the "cpcked" signal to be emitted.
cpcked This is emitted when the mouse button is pressed and released while the pointer is over the button or when the button is triggered with the keyboard.
Advertisements