c语言姓名如何定义,c语言如何输入编号和姓名

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#define NAME "root"

#define PAWD "123456"

struct login_widget

{

GtkWidget *window;

GtkWidget *label_tips;

GtkWidget *button_login;

GtkWidget *button_exit;

GtkWidget *entry_username;

GtkWidget *entry_password;

GtkWidget *label_username;

GtkWidget *label_password;

GtkWidget *vbox;

GtkWidget *hbox_username;

GtkWidget *hbox_password;

GtkWidget *hbox_button;

}wgt;

void login(GtkWidget *widget,gpointer data)

{

gchar *name;

gchar *pawd;

struct login_widget *wgt;

wgt=(struct login_widget*)data;

name=gtk_entry_get_text(GTK_ENTRY(wgt->entry_username));

pawd=gtk_entry_get_text(GTK_ENTRY(wgt->entry_password));

if(!strcmp(name,NAME)&&!strcmp(pawd,PAWD))

gtk_label_set_text(GTK_LABEL(wgt->label_tips),

"Welcome to GTK!");

else

gtk_label_set_text(GTK_LABEL(wgt->label_tips),

"Failed to login!");

}

void init_login_widget()

{

wgt.window=gtk_window_new(GTK_WINDOW_TOPLEVEL);

wgt.label_tips=gtk_label_new("Welcome,please login");

wgt.button_login=gtk_button_new_with_label("login");

wgt.button_exit=gtk_button_new_with_label("exit");

wgt.entry_username=gtk_entry_new_with_max_length(10);

wgt.entry_password=gtk_entry_new_with_max_length(10);

wgt.label_username=gtk_label_new("User name:");

wgt.label_password=gtk_label_new("Password:");

wgt.vbox=gtk_vbox_new(FALSE,20);

wgt.hbox_username=gtk_hbox_new(FALSE,20);

wgt.hbox_password=gtk_hbox_new(FALSE,20);

wgt.hbox_button=gtk_hbox_new(FALSE,20);

gtk_window_set_title(GTK_WINDOW(wgt.window),"Login");

gtk_window_set_resizable(GTK_WINDOW(wgt.window),FALSE);

gtk_box_pack_start(GTK_BOX(wgt.hbox_username),

wgt.label_username,TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.hbox_username),

wgt.entry_username,TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.hbox_password),

wgt.label_password,TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.hbox_password),

wgt.entry_password,TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.hbox_button),

wgt.button_login,TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.hbox_button),

wgt.button_exit,TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.vbox),wgt.label_tips,

TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.vbox),wgt.hbox_username,

TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.vbox),wgt.hbox_password,

TRUE,FALSE,10);

gtk_box_pack_start(GTK_BOX(wgt.vbox),wgt.hbox_button,

TRUE,FALSE,10);

gtk_entry_set_visibility(GTK_ENTRY(wgt.entry_password),

FALSE);

gtk_entry_set_invisible_char(GTK_ENTRY(wgt.entry_password),

'*');

g_signal_connect(GTK_OBJECT(wgt.button_login),"clicked",

GTK_SIGNAL_FUNC(login),&wgt);

g_signal_connect(GTK_OBJECT(wgt.window),"destroy",

G_CALLBACK(gtk_main_quit),NULL);

g_signal_connect(GTK_OBJECT(wgt.button_exit),"clicked",

G_CALLBACK(gtk_main_quit),NULL);

gtk_container_add(GTK_CONTAINER(wgt.window),wgt.vbox);

gtk_widget_show_all(wgt.window);

}

int main(int argc,char **argv)

{

gtk_init(&argc,&argv);

init_login_widget();

gtk_main();

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值