Home > Archive > PerlTk > October 2007 > Hiding Browseentry dropdown
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 |
Hiding Browseentry dropdown
|
|
| trisha.woods@gmail.com 2007-10-02, 7:05 pm |
| Hi All,
I am using the BrowseEntry widget to provide a list of items to the
user. It calls a function (-listcmd) that populates the dropdown.
Based on some checks this function would popup an error window.
However, when this happens, both the dropdown and the error window
appear together and it appears messy.
I have these questions:
1. Is there a way to hide the dropdown list in case of error
2. How can I grab the focus on the error window such that unless the
user responds to the error message nothing can be done (please use
this example to demonstrate)
3. Is there a better way of doing these things?
I would appreciate any comments from you experts.
Thanks
Trisha
-------------------------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::BrowseEntry;
my $selection = "";
my $induce_error = 0;
my $mw = MainWindow->new();
$mw->title("BrowseEntry");
$mw->geometry('+0+0');
$mw->optionAdd('*BorderWidth' => 1);
my $be = $mw->BrowseEntry( -label => 'My List',
-variable => \$selection,
-state => 'readonly',
-width => '38',
-listcmd => [\&populate_list],
);
$be->pack( -side => 'top',
-padx => 6,
-pady => 2,
-expand => 0
);
my $error_cb = $mw->Checkbutton(
-text => "Induce Error",
-variable => \$induce_error,
-relief => "flat",
-borderwidth => 1,
-cursor => 'hand2',
)->pack(-side => 'top');
MainLoop();
sub populate_list {
if ($induce_error == 1) {
&error("GOT AN INTERNAL ERROR");
return(-1);
}# if
$be->delete(0, 'end');
foreach ("One","Two", "Three") {
$be->insert('end', $_);
}# foreach
$be->raise();
}# sub
sub error {
my $msg = shift;
my $error = MainWindow->new();
$error->minsize(qw(150 100));
$error->title("ERROR!!");
$error->geometry('+0+0');
my $h_m = $error->Message(-text => $msg, -width => '8i', -relief =>
'groove', -borderwidth => 2, -background => 'red')->pack(-side =>
'top', -pady => 10);
my $h_b = $error->Button(-text => 'OK', -foreground => 'black', -
activebackground=>'yellow', -command => sub{$error->destroy})->pack(-
side => 'bottom', -pady=>3);
MainLoop();
}# sub
##################END###################
##
| |
| Lamprecht 2007-10-02, 7:05 pm |
| trisha.woods@gmail.com schrieb:
> Hi All,
> I am using the BrowseEntry widget to provide a list of items to the
> user. It calls a function (-listcmd) that populates the dropdown.
> Based on some checks this function would popup an error window.
> However, when this happens, both the dropdown and the error window
> appear together and it appears messy.
>
> I have these questions:
> 1. Is there a way to hide the dropdown list in case of error
> 2. How can I grab the focus on the error window such that unless the
> user responds to the error message nothing can be done (please use
> this example to demonstrate)
> 3. Is there a better way of doing these things?
Hi,
use Tk::break to return immediately from a callback.
Use a Dialog (or something similar) for an error message.
HTH, Christoph
use strict;
use warnings;
use Tk;
use Tk::BrowseEntry;
my $selection = "";
my $induce_error = 0;
my $mw = MainWindow->new();
$mw->title("BrowseEntry");
$mw->geometry('+0+0');
$mw->optionAdd('*BorderWidth' => 1);
my $be = $mw->BrowseEntry( -label => 'My List',
-variable => \$selection,
-state => 'readonly',
-width => '38',
-listcmd => [\&populate_list],
);
$be->pack( -side => 'top',
-padx => 6,
-pady => 2,
-expand => 0
);
my $error_cb = $mw->Checkbutton(
-text => "Induce Error",
-variable => \$induce_error,
-relief => "flat",
-borderwidth => 1,
-cursor => 'hand2',
)->pack(-side => 'top');
MainLoop();
sub populate_list {
if ($induce_error == 1) {
&error("GOT AN INTERNAL ERROR");
return(-1);
}# if
$be->delete(0, 'end');
foreach ("One","Two", "Three") {
$be->insert('end', $_);
}# foreach
$be->raise();
}# sub
sub error {
my $msg = shift;
my $error = MainWindow->new();
$error->minsize(qw(150 100));
$error->title("ERROR!!");
$error->geometry('+0+0');
my $h_m = $error->Message(-text => $msg, -width => '8i', -relief =>
'groove', -borderwidth => 2, -background => 'red')->pack(-side =>
'top', -pady => 10);
my $h_b = $error->Button(-text => 'OK', -foreground => 'black', -
activebackground=>'yellow', -command => sub{$error->destroy})->pack(-
side => 'bottom', -pady=>3);
MainLoop();
}# sub
| |
| trisha.woods@gmail.com 2007-10-02, 7:05 pm |
|
> Hi,
> use Tk::break to return immediately from a callback.
> Use a Dialog (or something similar) for an error message.
>
> HTH, Christoph
Thanks for the reply Chris. Your Tk::break worked just fine - Thanks
for that.
I thought, using the seperate window for displaying a messages (e.g.
error) would be a generic solution. Because, there are cases where I
display more details to the user (rather than just an error message).
I'm not sure if Dialog window will look good as it displays everything
in bigger fonts. Is there a way to configure the fonts and background
color for the diaglog?
Thanks
~Trisha
| |
| Lamprecht 2007-10-02, 7:05 pm |
| trisha.woods@gmail.com schrieb:
>
> Thanks for the reply Chris. Your Tk::break worked just fine - Thanks
> for that.
> I thought, using the seperate window for displaying a messages (e.g.
> error) would be a generic solution. Because, there are cases where I
> display more details to the user (rather than just an error message).
> I'm not sure if Dialog window will look good as it displays everything
> in bigger fonts. Is there a way to configure the fonts and background
> color for the diaglog?
>
> Thanks
> ~Trisha
>
Hi,
you can add a -font configure option to the Dialog constructor providing
a Tk::Font description ( see perldoc Tk::Font ):
-font => ['Helvetica',11,'normal'],
Also read perldoc Tk::Dialog
perldoc Tk::DialogBox
perldoc Tk::Message
perldoc Tk::messageBox
HTH, Christoph
| |
| trisha.woods@gmail.com 2007-10-03, 7:05 pm |
| Thanks Chris.
| |
| trisha.woods@gmail.com 2007-10-03, 7:05 pm |
| I ended up using Tk:messageBox. I am using a function call to
messageBox to display the message (shown below). How could I grab the
focus to the messageBox such that unless the user responds to it
nothing can be done with the main window?
sub send_message{
my $message = shift;
$mw->messageBox(
-background => 'lightyellow',
-foreground => 'red',
-message => $message,
-font => ['Helvetica',10,'normal'],
-type => 'OK'
);
}
~Trisha
| |
| Lamprecht 2007-10-03, 7:05 pm |
| trisha.woods@gmail.com schrieb:
> I ended up using Tk:messageBox. I am using a function call to
> messageBox to display the message (shown below). How could I grab the
> focus to the messageBox such that unless the user responds to it
> nothing can be done with the main window?
>
> sub send_message{
> my $message = shift;
> $mw->messageBox(
> -background => 'lightyellow',
> -foreground => 'red',
> -message => $message,
> -font => ['Helvetica',10,'normal'],
> -type => 'OK'
> );
> }
Hi,
I see messageBox grabbing focus as expected here...
Christoph
| |
| trisha.woods@gmail.com 2007-10-03, 7:05 pm |
| That's correct, but this is the problem that I'm facing.
I have a main window (MW1). From the menu, a user can select "options"
which opens another main window(MW2). In MW2(options window) the user
can select a directory path. If the directory entered is not correct I
popup an error message. Now, When I call the function send_message()
only MW1 loses its grab, but MW2 still has a grab. Is there a way I
can prevent this?
~Trisha
| |
| Lamprecht 2007-10-04, 4:09 am |
| trisha.woods@gmail.com schrieb:
> That's correct, but this is the problem that I'm facing.
> I have a main window (MW1). From the menu, a user can select "options"
> which opens another main window(MW2). In MW2(options window) the user
> can select a directory path. If the directory entered is not correct I
> popup an error message. Now, When I call the function send_message()
> only MW1 loses its grab, but MW2 still has a grab. Is there a way I
> can prevent this?
>
> ~Trisha
>
Don't use a second MainWindow, use a Toplevel for MW2. (Or maybe another
Dialog).
Christoph
| |
| trisha.woods@gmail.com 2007-10-04, 7:04 pm |
| On Oct 3, 11:49 pm, Lamprecht <ch.l.ngre-nos...@online.de> wrote:
> trisha.wo...@gmail.com schrieb:
>
>
>
> Don't use a second MainWindow, use a Toplevel for MW2. (Or maybe another
> Dialog).
>
> Christoph
Thanks a lot Christoph. That did work for me.
Thanks
~Trish
|
|
|
|
|