Sample Code 169: How to set default button of GtkDialog - Part 1 - using set_default_response? |
|
Written by kksou
|
|
Thursday, 15 February 2007 |
|
Problem Suppose you have set up three buttons in a GtkDialog, and you want "Button 2" to be the default button when the user press Enter as shown below:

Solution
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?php $dialog = new GtkDialog(); $dialog->connect_simple('destroy', array( 'Gtk', 'main_quit')); $dialog->set_size_request(400,150);
// display title
$title = new GtkLabel("Set Default Button - Part 1\n". "using set_default_response"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $title->set_justify(Gtk::JUSTIFY_CENTER); $alignment = new GtkAlignment(0.5, 0, 0, 0); $alignment->add($title); $dialog->vbox->pack_start($alignment, 0, 0); $dialog->vbox->pack_start(new GtkLabel(), 0, 0);
$dialog->add_buttons(array('button 1', 100, // note 1
'button 2', 101, 'button 3', 102));
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Create the buttons.
- Here we specify button 2 (response ID 101) as the default button.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |