Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl TK related (manupulating the output text area)

Reply
Thread Tools

perl TK related (manupulating the output text area)

 
 
king
Guest
Posts: n/a
 
      06-02-2006
#!\c\perl\bin
use Tk;

my $mw = new MainWindow; # Main Window

my $frm_name = $mw -> Frame() -> pack();
my $lab = $frm_name -> Label(-text=>"Name:") -> pack();
my $ent = $frm_name -> Entry() -> pack();

my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button) ->
pack();
#Text Area
my $txt = $mw -> Text(-width=>50, -height=>30) -> pack();

MainLoop;

#This function will be executed when the button is pushed
sub push_button {
my $name = $ent -> get();
$txt -> insert('end',"Hello, $name.");
}

1.as soon as i run this script
a window opens
But the cursor is not on the name block
Question- Can it be possible that as soon as the window opens the
cursor should be present in the name block.

again
2. suppose once i typed a name,it will show up with hellow then the
$name.
but in the same window if I again give some other name in the name
block,
the hellow $ name is coming next to the previous test messege in the
text area.
Question
Each time I give a input and then enter button push me the only text
present there should be hellow and the recent name entered.
Can it be possible to do that.

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      06-02-2006
king wrote:
> #!\c\perl\bin
> use Tk;
>
> my $mw = new MainWindow; # Main Window
>
> my $frm_name = $mw -> Frame() -> pack();
> my $lab = $frm_name -> Label(-text=>"Name:") -> pack();
> my $ent = $frm_name -> Entry() -> pack();
>
> my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button) ->
> pack();
> #Text Area
> my $txt = $mw -> Text(-width=>50, -height=>30) -> pack();
>
> MainLoop;
>
> #This function will be executed when the button is pushed
> sub push_button {
> my $name = $ent -> get();
> $txt -> insert('end',"Hello, $name.");
> }
>
> 1.as soon as i run this script
> a window opens
> But the cursor is not on the name block
> Question- Can it be possible that as soon as the window opens the
> cursor should be present in the name block.


Add the line:
$ent->focus();
right before MainLoop;

> again
> 2. suppose once i typed a name,it will show up with hellow then the
> $name.
> but in the same window if I again give some other name in the name
> block,
> the hellow $ name is coming next to the previous test messege in the
> text area.
> Question
> Each time I give a input and then enter button push me the only text
> present there should be hellow and the recent name entered.
> Can it be possible to do that.


Yes. Just delete the text that's currently in the box right before you
insert the new text. Look up the widget's delete() method at
http://search.cpan.org/~ni-s/Tk-804....WIDGET_METHODS

Paul Lalli

 
Reply With Quote
 
 
 
 
Brian Raven
Guest
Posts: n/a
 
      06-02-2006
"king" <(E-Mail Removed)> writes:

> #!\c\perl\bin


Missing "use strict; use warnings;"

> use Tk;
>
> my $mw = new MainWindow; # Main Window
>
> my $frm_name = $mw -> Frame() -> pack();
> my $lab = $frm_name -> Label(-text=>"Name:") -> pack();
> my $ent = $frm_name -> Entry() -> pack();
>
> my $but = $mw -> Button(-text=>"Push Me", -command =>\&push_button) ->
> pack();
> #Text Area
> my $txt = $mw -> Text(-width=>50, -height=>30) -> pack();
>
> MainLoop;
>
> #This function will be executed when the button is pushed
> sub push_button {
> my $name = $ent -> get();
> $txt -> insert('end',"Hello, $name.");
> }
>
> 1.as soon as i run this script
> a window opens
> But the cursor is not on the name block
> Question- Can it be possible that as soon as the window opens the
> cursor should be present in the name block.


See 'perldoc Tk::focus'

>
> again
> 2. suppose once i typed a name,it will show up with hellow then the
> $name.
> but in the same window if I again give some other name in the name
> block,
> the hellow $ name is coming next to the previous test messege in the
> text area.


Well, that is what you told it to do.

> Question
> Each time I give a input and then enter button push me the only text
> present there should be hellow and the recent name entered.
> Can it be possible to do that.
>


Then you have to delete what was already there before inserting a new
string. Look for the delete function in 'perldoc Tk::Text'.

HTH

--
Brian Raven

That which hits the fan tends to get flung in all directions.
-- Larry Wall in <(E-Mail Removed)>
 
Reply With Quote
 
zentara
Guest
Posts: n/a
 
      06-02-2006
On 2 Jun 2006 01:53:40 -0700, "king" <(E-Mail Removed)> wrote:

Script snipped. This should do what you want.

#!/usr/bin/perl
use warnings;
use strict;
use Tk;

my $mw = new MainWindow; # Main Window

my $frm_name = $mw -> Frame() -> pack();
my $lab = $frm_name -> Label(-text=>"Name:") -> pack();
my $ent = $frm_name -> Entry() -> pack();

my $but = $mw -> Button(-text=>"Push Me",
-command =>\&push_button) ->pack();

#Text Area
my $txt = $mw -> Text(-width=>50, -height=>30) -> pack();

$ent->focus;

MainLoop;

#This function will be executed when the button is pushed

sub push_button {
my $name = $ent -> get();
$txt -> insert('end',"Hello, $name.\n");
$ent->delete(0,'end');
}
__END__




--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPP Output Question - related to copy-constructor and return by value sanjay C++ 1 10-09-2008 01:16 PM
How should multiple (related) projects be arranged (structured) and configured so that they can share code, have a related package structure and enable proper unittesting, and ensuring no namespace collisions ToddLMorgan@gmail.com Python 14 04-21-2006 04:03 PM
replacing text at the beginning of a file in perl and appending to that output aixenv@yahoo.com Perl Misc 3 07-20-2005 06:17 PM
How should threads be terminated? (related to 'Help with thread related tracebacks') Maxwell Hammer Python 7 06-18-2005 04:20 PM
Understanding java error output - related to the sun app server PE 8.1 gonzalobriceno@gmail.com Java 1 06-07-2005 04:27 PM



Advertisments