Re: Getting text from gtk_entry

From: Date: Fri, 03 Aug 2001 12:18:54 +0000
Subject: Re: Getting text from gtk_entry
References: 1  Groups: php.gtk 
Request: Send a blank email to php-gtk+get-2486@lists.php.net to get a copy of this message
> > below is a snippet and atached is the full script thus far :) > > function pref_window() { > global $username,$password,$host; > $query = &new GtkDialog(); > $query->set_title('Preferences'); > $query->set_default_size(150, 250); > > > $username = &new GtkEntry(); > $vbox = $query->vbox; > $vbox->pack_start($username, TRUE, TRUE, 0); > $username->show(); > > $okbutton = &new GtkButton('Save Settings'); > $okbutton->connect('clicked', write_preferences); > $okbutton->connect_object('clicked', array($query, 'destroy')); > $query->connect('delete_event', create_function('', > 'gtk::main_quit();')); Ah....your destroying the window when the user presses the OK button. That's going to make it a little tricky! I would suggest that you handle the destruction in the write_preferences function, and pass the function the dialog object itself. Something like: $okbutton->connect('clicked', write_preferences,$query,$username); > $action_area = $query->action_area; > $action_area->pack_start($okbutton, TRUE, TRUE, 0); > $okbutton->show(); > > $query->show_all(); > > > } > > function write_preferencesa(){ > global $username; > $user = $username->get_text(); > echo "$user:$username"; > } OK, then this would look something likeL function write_preferencesa($widget, $dialog, $text_entry){ $user = $text_entry->get_text(); echo "$user\n"; $dialog->destroy(); } Note that $widget is the button that created the event, you are always passed that. and FWIW, I think $text_entry->get_text() is supposed to be $text_entry->get_chars(0,-1). It says in the GTK+ docs that get_text() is depricated and get_chars(start_pos, end_pos) should be used instead. Does that help? -- Rich Payne rpayne@alphalinux.org www.alphalinux.org

« previous php.gtk (#2486) next »