3、GtkTable 表格布局控件
复制内容到剪贴板
代码:
<?
$w = new GtkWindow();
$w->set_title('GtkTable test');
$w->connect_simple('destroy', array('gtk', 'main_quit'));
$lbl1 = new GtkLabel('Email address:');
$lbl2 = new GtkLabel('Id:');
$lbl3 = new GtkLabel('Name:');
$align3 = new GtkAlignment(0.0, 0.5, 0, 0);
$align3->add($lbl3);
$txt1 = new GtkEntry();
$txt2 = new GtkEntry();
$txt3 = new GtkEntry();
$table = new GtkTable(3, 2); // 创建一个3行2列的表格布局控件
$table->attach($lbl1 , 0, 1, 0, 1, 0); // 把lbl1装入到表格的第一行第一列中
/*
attach的函数原形
void attach(GtkWidget child,
int left_attach,
int right_attach,
int top_attach,
int bottom_attach [,
GtkAttachOptions xoptions = Gtk::EXPAND|Gtk::FILL [,
GtkAttachOptions yoptions = Gtk::EXPAND|Gtk::FILL [,
int xpadding = Gtk::EXPAND|Gtk::FILL [,
int ypadding = Gtk::EXPAND|Gtk::FILL]]]]);
0,1,0,1,0 的意思就是说 lbl1所占用的空间是这样的
0-----------------1---------------------2
| lbl1 | |
| | |
1---------------------------------------|
| | |
| | |
2---------------------------------------|
| | |
| | |
3---------------------------------------|
*/
$table->attach($lbl2 , 0, 1, 1, 2, 0);
$table->attach($align3, 0, 1, 2, 3, Gtk::FILL);
$table->attach($txt1 , 1, 2, 0, 1);
$table->attach($txt2 , 1, 2, 1, 2);
$table->attach($txt3 , 1, 2, 2, 3);
$w->add($table);
$w->show_all();
Gtk::main();
?> 经常有人说布局很麻烦,其实不是这样的,熟能生巧,多用多练,自然就用的熟练了