关于按钮的提问

wenshi198216 2004-05-05 10:34:18
我想创建按钮button1,在其中显示一张图片,按下按钮后显示另一张图片。如下
可是第二张图片显示不出来,请帮忙看看把,谢谢

#include <gdk/gdk.h>
#include <gtk/gtk.h>


GtkWidget *window;
GtkWidget *table;
GtkWidget *button1;
GtkWidget *table;
GtkWidget *box1;

/*创建box并在其中加入图片
GtkWidget *xpm_label_box(GtkWidget *parent, gchar *xpm_filename )
{
GtkWidget *box;
GtkWidget *pixmapwid;
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkStyle *style;

box = gtk_hbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (box), 2);
style=gtk_widget_get_style(parent);
pixmap=gdk_pixmap_create_from_xpm(parent->window,&mask,&style->bg[GTK_STATE_NORMAL],
xpm_filename);
pixmapwid=gtk_pixmap_new(pixmap,mask);
gtk_box_pack_start (GTK_BOX (box), pixmapwid, TRUE, TRUE, 3);
gtk_widget_show (pixmapwid);
return box;
}

/*按钮被按后的回调函数
void pressedm()
{
box1=xpm_label_box (window,"amant.xpm");
gtk_widget_show (box1);
gtk_container_add (GTK_CONTAINER (button1), box1);
gtk_table_attach_defaults (GTK_TABLE (table), button1, 24,28, 41, 46);
}

/*主函数
int main(int argc, char *argv[])
{

gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);

/*设置窗口的大小
gint width=600;
gint height=455;
gtk_widget_set_usize(window,width,height);
/*创建table
table = gtk_table_new (50,30, TRUE);
gtk_container_add (GTK_CONTAINER (window), table);

/*创建按钮
button1= gtk_button_new ();
box1 = xpm_label_box (window,"maint.xpm");
gtk_widget_show (box1);
gtk_container_add (GTK_CONTAINER (button1), box1);
gtk_table_attach_defaults (GTK_TABLE (table), button1, 24,28, 41, 46);
gtk_signal_connect (GTK_OBJECT (button1), "pressed",GTK_SIGNAL_FUNC(pressedm), NULL);

gtk_widget_show (button1);

gtk_widget_show (table);

gtk_widget_show(window);

gtk_main();

return 0;


}

...全文
8 回复 点赞 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Linux/Unix社区
加入

2.1w+

社区成员

Linux/Unix社区 应用程序开发区
申请成为版主
帖子事件
创建了帖子
2004-05-05 10:34
社区公告
暂无公告