For Programmers: Free Programming Magazines  


Home > Archive > PerlTk > October 2007 > Can't enter into Entry widget









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Can't enter into Entry widget
Bernie Cosell

2007-10-27, 7:07 pm

I'm clearly missing something, because in the program attached below I
can't get the Entry widget to accept in. BUT: if I comment out the line
with the getOpenFile on it, the Entry widget works perfectly. I can't
figure out what I'm doing wrong here:

Thanks!
/Bernie\

#!/usr/bin/perl

use strict ;
use warnings ;
use Tk ;
use vars qw($mw) ;
$mw = MainWindow->new;

use vars qw($idframe $idEntry) ;
$idframe = $mw->Frame ;
$idframe->Entry(-width => 50, -textvariable => \$idEntry
)->pack;
$idframe->Button(-text => 'Go', -command => \&GetEntry
)->pack;

use vars qw($DBname) ;
# Commenting out the next line allows the Entry widget to work.
my $DBname = $mw->getOpenFile(-title => "CD databse");

$idframe->pack ;
MainLoop ;

sub GetEntry
{ my $ident = $idEntry ;
return unless $ident ;
Modal("Click", "Got '$ident'") ;
return ;
}

sub Modal
{ $mw->Dialog(-text => $_[1],
-default_button => 'OK',
-buttons => [ 'OK' ])->Show ;
}

--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
felix.da.ru

2007-10-27, 7:07 pm


Bernie Cosell:
> I'm clearly missing something, because in the program attached below I
> can't get the Entry widget to accept in. BUT: if I comment out the line
> with the getOpenFile on it, the Entry widget works perfectly. I can't
> figure out what I'm doing wrong here:
>
> Thanks!
> /Bernie\
>
> #!/usr/bin/perl
>
> use strict ;
> use warnings ;
> use Tk ;
> use vars qw($mw) ;
> $mw = MainWindow->new;
>
> use vars qw($idframe $idEntry) ;
> $idframe = $mw->Frame ;
> $idframe->Entry(-width => 50, -textvariable => \$idEntry
> )->pack;
> $idframe->Button(-text => 'Go', -command => \&GetEntry
> )->pack;
>
> use vars qw($DBname) ;
> # Commenting out the next line allows the Entry widget to work.
> my $DBname = $mw->getOpenFile(-title => "CD databse");
>
> $idframe->pack ;
> MainLoop ;
>
> sub GetEntry
> { my $ident = $idEntry ;
> return unless $ident ;
> Modal("Click", "Got '$ident'") ;
> return ;
> }
>
> sub Modal
> { $mw->Dialog(-text => $_[1],
> -default_button => 'OK',
> -buttons => [ 'OK' ])->Show ;
> }
>
> --
> Bernie Cosell Fantasy Farm Fibers
> bernie@fantasyfarm.com Pearisburg, VA
> --> Too many people, too few sheep <--


Wait, how you think this will work? Without running MainLoop you are
trying to fire some interactive GUI things?...
It's not miracle that this code fails. You should consider following
basic rule: all code that runs BEFORE MainLoop is just geometry
arrangement methods. All "real kicking" part must run AFTER MainLoop
called.
If your goal is just to run "getOpenFile" immediately after main
window open - use "after" method:

my $DBname;
....

$mw->after(100,{ $DBname = $mw->getOpenFile(-title => "CD
databse"); });

MainLoop;

Bernie Cosell

2007-10-28, 7:09 pm

"felix.da.ru" <felix.liberman@gmail.com> wrote:

} Bernie Cosell:
} > I'm clearly missing something, because in the program attached below I
} > can't get the Entry widget to accept in.

} > $mw = MainWindow->new;
} >
} > use vars qw($idframe $idEntry) ;
} > $idframe = $mw->Frame ;
} > $idframe->Entry(-width => 50, -textvariable => \$idEntry
} > )->pack;
} > $idframe->Button(-text => 'Go', -command => \&GetEntry
} > )->pack;
} >
} > use vars qw($DBname) ;
} > # Commenting out the next line allows the Entry widget to work.
} > my $DBname = $mw->getOpenFile(-title => "CD databse");
} >
} > $idframe->pack ;
} > MainLoop ;

} Wait, how you think this will work? Without running MainLoop you are
} trying to fire some interactive GUI things?...

Yup -- needed to get a DB to DBI_connect to...

} If your goal is just to run "getOpenFile" immediately after main
} window open - use "after" method:

Exactly the problem I was struggling with: before I do the "real" MainLoop
[that is, wait for an event to happen], I needed to get the proper
database to connect to. What I missed was the 'after' method!! Thanks! I
had tried just sticking the getOpenFile before the MainLoop and in one
program it worked perfectly [no "Entry" in that program..:o)] but I ran
into this wierd Entry problem...

} my $DBname;
} ...
}
} $mw->after(100,{ $DBname = $mw->getOpenFile(-title => "CD
} databse"); });

Got it. THANKS!!

/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com