Mouse Click Bind for an Entry Widget 
Author Message
 Mouse Click Bind for an Entry Widget

Hi,
    I have an app that uses a table filled with entrys to make a kind of
spreadsheet looking app. What i'd like to be able to do is click on an
entry, and use a callback to do stuff to that entry. My code is below, in
which i'm just changing the bg color of the entry box. I'm not entirely sure
about the bind statement, and think this is probably where the problem lies.
Can anyone see what my mistakes are?

 $entry =
$table->Entry(-textvariable=>\$temp_sym,-relief=>'flat',-bg=>'grey');
 $mainwindow->bind($entry,'ButtonRelease',[\&CellSelect, \$ent]);

sub CellSelect {

 $ent->configure(-bg=>'blue');

Quote:
}

Also, is there a 'fork' type routine specific to Tk, that can run background
processes?

Cheers
salukibob



Mon, 17 Jan 2005 16:09:31 GMT  
 Mouse Click Bind for an Entry Widget

Quote:
> Hi,
>     I have an app that uses a table filled with entrys to make a kind of
> spreadsheet looking app. What i'd like to be able to do is click on an
> entry, and use a callback to do stuff to that entry. My code is below, in
> which i'm just changing the bg color of the entry box. I'm not entirely sure
> about the bind statement, and think this is probably where the problem lies.
> Can anyone see what my mistakes are?

>  $entry =
> $table->Entry(-textvariable=>\$temp_sym,-relief=>'flat',-bg=>'grey');
>  $mainwindow->bind($entry,'ButtonRelease',[\&CellSelect, \$ent]);

Use the following syntax to bind the entry:

$entry->bind('<ButtonRelease>',\&CellSelect);

The bind command will automatically pass the reference to the entry object as
the first parameter.

Quote:

> sub CellSelect {

>  $ent->configure(-bg=>'blue');
> }

You might reconsider to use FocusIn and FocusOut instead - this will allow the
use of change the color of the currently focussed widget evening if arrived at
by tabbing.

#### Example ####
use Tk;
use strict;

my $mw=tkinit;
foreach (0..9){
 my $e=$mw->Entry(-bg=>'grey')->pack;
 $e->bind('<FocusIn>',[sub{$_[0]->configure(-bg=>'blue')}]);
 $e->bind('<FocusOut>',[sub{$_[0]->configure(-bg=>'grey')}]);

Quote:
}

MainLoop;
#### End Example ####

Quote:

> Also, is there a 'fork' type routine specific to Tk, that can run background
> processes?

Steve Lidie wrote a module called Tk::ExecuteCommand in Mastering Perl/Tk. A
google search for 'ExecuteCommand' should give you the information you need.

Jack



Tue, 18 Jan 2005 08:20:24 GMT  
 Mouse Click Bind for an Entry Widget

Quote:


> > Hi,
> >     I have an app that uses a table filled with entrys to make a kind of
> > spreadsheet looking app. What i'd like to be able to do is click on an
> > entry, and use a callback to do stuff to that entry. My code is below,
in
> > which i'm just changing the bg color of the entry box. I'm not entirely
sure
> > about the bind statement, and think this is probably where the problem
lies.
> > Can anyone see what my mistakes are?

> >  $entry =
> > $table->Entry(-textvariable=>\$temp_sym,-relief=>'flat',-bg=>'grey');
> >  $mainwindow->bind($entry,'ButtonRelease',[\&CellSelect, \$ent]);

> Use the following syntax to bind the entry:

> $entry->bind('<ButtonRelease>',\&CellSelect);

> The bind command will automatically pass the reference to the entry object
as
> the first parameter.

> > sub CellSelect {

> >  $ent->configure(-bg=>'blue');
> > }

> You might reconsider to use FocusIn and FocusOut instead - this will allow
the
> use of change the color of the currently focussed widget evening if
arrived at
> by tabbing.

> #### Example ####
> use Tk;
> use strict;

> my $mw=tkinit;
> foreach (0..9){
>  my $e=$mw->Entry(-bg=>'grey')->pack;
>  $e->bind('<FocusIn>',[sub{$_[0]->configure(-bg=>'blue')}]);
>  $e->bind('<FocusOut>',[sub{$_[0]->configure(-bg=>'grey')}]);
> }
> MainLoop;
> #### End Example ####

> > Also, is there a 'fork' type routine specific to Tk, that can run
background
> > processes?

> Steve Lidie wrote a module called Tk::ExecuteCommand in Mastering Perl/Tk.
A
> google search for 'ExecuteCommand' should give you the information you
need.

> Jack

Thank you very much, that did the job perfectly.

Regards
salukibob



Tue, 18 Jan 2005 17:03:31 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Please help: Binding mouse click to tree entry.

2. binding mouse clicks to Tk::Columns

3. binding right mouse button click to all buttons

4. overriding default right mouse button binding for text widget

5. Binding a right-click in a text widget

6. Binding event to entry widget

7. how to bind return key to entry widget

8. binding a comand on an entry widget (again a newbie question)

9. Bind, Entry widgets and the MS Windows Manager

10. Bind & Entry widgets

11. simulating a mouse click?

12. Sending keystrokes and mouse click under WinPerl

 

 
Powered by phpBB® Forum Software