PHP-GTK2 Newsletter

PHP-GTK2 Tips & Techniques
FREE Newsletter
by kksou



Sample Code 2: How to change the size of GtkWindow?
Written by kksou   
Tuesday, 12 September 2006
Problem

You want to change the size of GtkWindow as shown below:

How to change the size of GtkWindow?


Solution
Use GtkWidget::set_size_request (int width, int height)
$window->set_size_request(400, 100);

Sample Code
1   
2   
3   
4   
5   
6   
7   
<?php
$window = new GtkWindow();
$window->set_size_request(400, 100);

$window->connect_simple('destroy', array('Gtk','main_quit'));
$label = new GtkLabel("hello world!");
$window->add($label);
  • 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
  • $window->set_size_request(400,100) sets the window size to width=400, height=100.

  • If you set only the width, e.g. $window->set_size_request(400,-1) you will get:

  • How to 0002?

    Note that GTK will adjust the height for you automically to fit the height of the label.

  • If you set only the height, e.g. $window->set_size_request(-1,100) you will get:

  • How to 0002?


Notes

set_size_request works on most other widgets, including hbox, vbox, buttons, labels, etc.

For example, you can use $label->set_size_request(48,36) to set the size of a label.

 

Add comment


Security code
Refresh

< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved