gtk里设置窗口大小的与位置的函数怎么用? 刚开始学gtk,求大神解释!!!

2024-11-26 00:11:12
推荐回答(2个)
回答1:

gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);//设置窗口在屏幕中间,
你函数的参数有问题。

回答2:

把你的char title[]="label example.";改成char *title="label example.";效率高点;
把你的gtk_widget_set_usize(GTK_WINDOW (window),400,200);改成gtk_widget_set_response(GTK_WINDOW (window),400,200);;
把你的return 0;改成return FALSE;这样规范点

在你的程序中,gtk_widget_set_uposition(GTK_WINDOW (window),200,200);这样的用法是错误的,多去看看帮助文档,里面是这样写的:gtk_widget_set_uposition is deprecated and should not be used in newly-written code.……Don't use this function to center dialogs over the main application window; most window managers will do the centering on your behalf if you call gtk_window_set_transient_for(), and it's really not possible to get the centering to work correctly in all cases from application code. But if you insist, use gtk_window_set_position() to set GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering manually.
也就是说叫你别把这个函数像你用的方法去用,如果实在想用的话就用use gtk_window_set_position() to set GTK_WIN_POS_CENTER_ON_PARENT