Code compiles...but doesn't work (user input w/ gtk_entry )
- From: "george carter" <cglobal25 hotmail com>
- To: gtk-list gnome org
- Subject: Code compiles...but doesn't work (user input w/ gtk_entry )
- Date: Sun, 10 Aug 2003 18:16:59 -0400
This compiles fine but doesn't function, it just returns an error. The
problem is in the CancelButton function. I want it to be called when the
user inputs something and want to clear the gtk_entry box. The CompareName
function prints out what I want, but I'd like some advice on comparing the
input with another word and maybe clearing the gtk_entry box when it returns
false. I'm sure there are safer ways to do it and it's probably found in
milions of programs but any advice would be appreciated.
/** boxinterface.c **/
#include <gtk/gtk.h>
void CloseTheApp ( GtkWidget * window, gpointer data )
{
gtk_main_quit ();
}
void CompareName ( GtkButton * OkButton, gpointer data )
{
g_print ("This function compares user names\n" );
}
void ClearEntry ( GtkButton * CancelButton, gpointer data )
{
/* THIS FUNCTION KEEPS RETURNING AN ERROR. IT COMPILES FINE W/OUT
ERRORS,
* I'D LIKE TO HAVE THIS FUNCTION CALLED WHEN A USER ENTERS SOMETHING AND
WANTS TO
* TO CLEAR THE DISPLAY. THE PREVIOUS FUNCTION WORKS BUT OF COURSE
DOESN'T RETURN
* ANYTHING TO THE GTK_ENTRY BOX */
GtkWidget * textentry ;
gtk_entry_set_text ( GTK_ENTRY ( textentry ), "" ) ;
}
GtkWidget * MakeWindow ()
{
GtkWidget * window;
window = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
gtk_container_set_border_width ( GTK_CONTAINER ( window ), 10 );
gtk_window_set_default_size ( GTK_WINDOW ( window ), 320, 80 );
gtk_window_set_title ( GTK_WINDOW ( window ), "Cervell 1.0" );
gtk_signal_connect ( GTK_OBJECT ( window ),
"destroy",
GTK_SIGNAL_FUNC ( CloseTheApp ),
NULL );
return window;
}
GtkWidget * MakeEntryBox ()
{
GtkWidget * box;
GtkWidget * widget;
GtkWidget * textentry ;
box = gtk_hbox_new ( TRUE, 5 );
widget = gtk_label_new ( "Please enter your name" );
gtk_box_pack_start ( GTK_BOX ( box ), widget, FALSE, TRUE, 0 );
textentry = gtk_entry_new ();
gtk_box_pack_start ( GTK_BOX ( box ), textentry, FALSE, TRUE, 0 );
return box;
}
GtkWidget * MakeButtons ()
{
GtkWidget * box;
GtkWidget * OkButton;
GtkWidget * CancelButton ;
box = gtk_hbox_new ( TRUE, 5 );
OkButton = gtk_button_new_with_label ( "Ok" );
gtk_box_pack_end ( GTK_BOX ( box ), OkButton, FALSE, TRUE, 0 );
CancelButton = gtk_button_new_with_label ( "Cancel" );
gtk_box_pack_end ( GTK_BOX ( box ), CancelButton, FALSE, TRUE, 0 );
gtk_signal_connect ( GTK_OBJECT ( OkButton ),
"pressed",
GTK_SIGNAL_FUNC ( CompareName ),
"pressed" ) ;
gtk_signal_connect ( GTK_OBJECT ( CancelButton ),
"pressed",
GTK_SIGNAL_FUNC ( ClearEntry ),
"pressed" ) ;
return box;
}
gint main ( gint argc, gchar * argv [] )
{
GtkWidget * window;
GtkWidget * mainbox;
GtkWidget * entrybox;
GtkWidget * buttonbox;
gtk_init ( &argc, &argv );
window = MakeWindow ();
entrybox = MakeEntryBox ();
buttonbox = MakeButtons ();
mainbox = gtk_vbox_new ( FALSE, 10 );
gtk_box_pack_start ( GTK_BOX ( mainbox ), entrybox, FALSE, FALSE, 0 );
gtk_box_pack_start ( GTK_BOX ( mainbox ), buttonbox, FALSE, FALSE, 0 );
gtk_container_add ( GTK_CONTAINER ( window ), mainbox );
gtk_widget_show_all ( window ) ;
gtk_main ();
return 0;
}
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]