2.3 Display the button in default size
Written by kksou   
Monday, 17 March 2008

Objective

By right, the default size of a GtkButton corresponds to the size of its label. However, as you have seen in the previous few examples, it is always displayed extending across the entire width of the screen as shown below:

2.31.gif

In this example, we will see how to display a button in its default size.

Overview

  • First create a GtkButton.
  • Then create a GtkHBox.
  • Pack the button inside the hbox, set expand=false.
  • Then pack the hbox inside the vbox, also set expand=false.

Sample Output

2.3.gif

Sample Code

1   
2   
3   
4   
5   
6   
7   
8   
9   
10   
<?php
$window = new GtkWindow();
$window->connect_simple('destroy',array('Gtk','main_quit'));
$window->set_size_request(200, 100);
$vbox = new GtkVBox();
$window->add($vbox);

$button = new GtkButton('button label');
$hbox = new GtkHBox();
$hbox->pack_start($button, false); // note 1
  • 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

  1. expand=false will ensure that the button does not expand horizontally in the hbox.
  2. expand=false will ensure that the button does not expand vertically in the vbox.

As a result, the button is displayed in its default size – at the top, left corner of the window.



User reviews

There are no user reviews yet.

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

Copyright © 2006-2008. kksou.com. All Rights Reserved