Re: Read contents of Gtk2::Entry and Gtk2::ComboBox when button is pressed

Thanks, that put an end to my confusion.

On Wed, Nov 24, 2010 at 9:30 AM, haratron <haratron gmail com> wrote:
Thanks, that put an end to my confusion.

On Sat, Nov 20, 2010 at 5:53 PM, Jeremy Volkening
<volkening mailshack com> wrote:
On Fri, 2010-11-19 at 18:52 +0200, haratron wrote:
I'm using Glade3 and Perl to make a Gtk GUI.
At the moment, I have 3 Gtk2::Entry and 3 Gtk2::ComboBox objects.
I want to read their contents when a button is pressed (the OK button).
To illustrate better, the user is entering his data (Entry) and makes
his selections (ComboBox) and hits a button that reads "OK" . At that
moment, I want to read in the contents of each Entry and Combobox.

Following is the code that I currently have (handles only one Entry
and one ComboBox). What changes should I do to accomplish the above?

One thing to note is that there are different ways to interface with the
Gtk2::ComboBox object depending on how it is constructed, and you seem
to be mixing them. If you create it using


you can use the helper functions "append_text" and "get_active_text" as
you have below. In this case your code to build the associated model is

If you create the Gtk2::ComboBox with the more fundamental


you can't use those helper functions and will need calls to
"get_active_iter" from the ComboBox and then "get_value" from the
associated model using the iter you retrieved and the column you want
(probably 0).

Reading from the Gtk2::Entry is simpler, and you already have the
correct code for that. You just need to move everything within the
'clicked' callback. See below:

$window= $builder->get_object('window1');

$window->signal_connect( "destroy" => sub {

$engine_cbox= $builder->get_object('combobox1');

The block of code below is unnecessary if you used the "new_text"
construcutor. If not, I don't think this is quite correct anyway - the
renderer should be added to a column, which can be appended to your
model. TreeViews and their associated models, columns, renderers, iters,
paths, etc can be one of the more difficult parts of Gtk to grasp. If
you need help with this, ask a separate question or look at the sample
code in the source package.

my $model1 = new Gtk2::ListStore('Glib::String');
my $renderer1 = new Gtk2::CellRendererText;
$engine_cbox->pack_start($renderer1, FALSE);
$engine_cbox->set_attributes($renderer1, text => 0);

my @listing = qw/a b c d/;

foreach $text (@listing) {
    $engine_cbox->append_text ($text)


move this into your 'clicked' callback
print "engine is $engine\n";

$source_Entry= $builder->get_object('entry1');

move this into your 'clicked' callback
# $sourceimg= $source_Entry->get_text;

# $source_Entry->signal_connect(changed => \&convert, $source_Entry);
$source_Entry->signal_connect(changed => \&convert, $source_Entry);

$button= $builder->get_object('button1');

$button->signal_connect('clicked' => sub {

    my ($button,$userdata) = @_;
     print "engine is $engine\n";

     $sourceimg= $source_Entry->get_text;
     print "sourceimg is $sourceimg\n";

     #Do whatever else you want with these values...



$builder =undef;



sub convert {
      ($widget, $data) = @_;
      $text = $data->get_text();
#     print "$text and $engine\n";

I've never used Glade so I can't help you further than this. If you
provide a full working sample of code it might be easier to answer your
question, but I hope this helps.


gtk-perl-list mailing list
gtk-perl-list gnome org

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]