求在linux系统上用GTK编写图形界面程序,要求用到窗口按钮标签容器和布局 30

要有全部源代码和功能说明... 要有全部源代码和功能说明 展开
 我来答
494996971_cxt
2010-01-19
知道答主
回答量:1
采纳率:0%
帮助的人:0
展开全部
void enter_callback( GtkWidget *widget,
GtkWidget *entry )
{
const gchar *entry_text;
entry_text = gtk_entry_get_text (GTK_ENTRY (entry));
printf("Entry contents: %s\n", entry_text);
}

void entry_toggle_editable( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_editable_set_editable (GTK_EDITABLE (entry),
GTK_TOGGLE_BUTTON (checkbutton)->active);
}

void entry_toggle_visibility( GtkWidget *checkbutton,
GtkWidget *entry )
{
gtk_entry_set_visibility (GTK_ENTRY (entry),
GTK_TOGGLE_BUTTON (checkbutton)->active);
}
/* 我们常见的回调函数 */
void callback( GtkWidget *widget,
gpointer data )
{
g_print ("Hello again - %s was pressed\n", (char *) data);
}
int main( int argc, char *argv[])
{
GtkWidget *window;

GtkWidget *ok;
GtkWidget *close;

GtkWidget *text_view;
GtkTextBuffer *buffer;

GtkWidget *vbox;
GtkWidget *hbox;

GtkWidget *halign;
GtkWidget *valign;

gtk_init(&argc, &argv);

//=============Build a window===========//
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 350, 280);
gtk_window_set_title(GTK_WINDOW(window), "Labyrinth");
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), G_OBJECT(window));
//=============Adjust layout============//
vbox = gtk_vbox_new(FALSE, 5);
valign = gtk_alignment_new(0, 1, 0, 0);
gtk_container_add(GTK_CONTAINER(vbox), valign);
gtk_container_add(GTK_CONTAINER(window), vbox);
hbox = gtk_hbox_new(TRUE, 3);
//=============Build tow button========//
ok = gtk_button_new_with_label("OK");
gtk_widget_set_size_request(ok, 70, 30);
gtk_container_add(GTK_CONTAINER(hbox), ok);
close = gtk_button_new_with_label("Close");
gtk_container_add(GTK_CONTAINER(hbox), close);
halign = gtk_alignment_new(1, 0, 0, 0);
close = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
gtk_container_add(GTK_CONTAINER(halign), hbox);
gtk_box_pack_start(GTK_BOX(vbox), halign, FALSE, FALSE, 0);
g_signal_connect_swapped (G_OBJECT (close), "clicked",
G_CALLBACK (gtk_widget_destroy),
window);
GTK_WIDGET_SET_FLAGS (close, GTK_CAN_DEFAULT);
gtk_widget_grab_default (close);
gtk_widget_show (close);

//=============Build a TestView==========//
text_view=gtk_text_view_new();/*创建文本框构件*/
gtk_widget_set_size_request(text_view,200,200);
gtk_container_add(GTK_CONTAINER(window),vbox);
gtk_box_pack_start(GTK_BOX(vbox),text_view,FALSE,FALSE,0);
buffer=gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
gtk_widget_show(text_view);
//=============================
GtkWidget *entry;
gint tmp_pos;

entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (entry), 50);

g_signal_connect (G_OBJECT (entry), "OK",
G_CALLBACK (enter_callback), entry);
gtk_entry_set_text (GTK_ENTRY (entry), "hello");
tmp_pos = GTK_ENTRY (entry)->text_length;
gtk_editable_insert_text (GTK_EDITABLE (entry), " world", -1, &tmp_pos);
gtk_editable_select_region (GTK_EDITABLE (entry),
0, GTK_ENTRY (entry)->text_length);

// tmp_pos = GTK_ENTRY (entry)->text_length;
// gtk_editable_insert_text (GTK_EDITABLE (entry), " hello ", -1, &tmp_pos);
// gtk_editable_select_region (GTK_EDITABLE (entry),
// 0, GTK_ENTRY (entry)->text_length);

gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);

gtk_widget_show (entry);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
zhhzm
2010-01-07 · TA获得超过125个赞
知道答主
回答量:164
采纳率:0%
帮助的人:81.6万
展开全部
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式