in reply to Re: How to validate text in Text widge
in thread How to validate text in Text widge

Can you please give an example how to disable the entry of ';', i.e. when it is pressed, it will not be entered to the text box

Can you give an example how Scrolled can be changed dynamically according to amount of text entered?

Thanks
  • Comment on Re^2: How to validate text in Text widge

Replies are listed 'Best First'.
Re^3: How to validate text in Text widge ( Tk::NoOp )
by Anonymous Monk on Jan 03, 2016 at 20:59 UTC
    #!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = tkinit; my $tt = $mw->Scrolled('Text')->pack; $tt->bind( '<Key>' => sub { warn $Tk::event->k, ' ', $Tk::event->K; } +, ); $tt->bind( 'Tk::Text' => '<Key-semicolon>' => 'NoOp' ); $tt = $mw->Scrolled('Text')->pack; $tt->bind( 'Tk::Text' => '<Key-semicolon>' => sub { warn 'semicolon re +jected '; return !!0; } ); $mw->WidgetDump; use Tk::WidgetDump; $tt->focus; $mw->MainLoop;
      Thanks!, Exactly what I needed, and very helpful
Re^3: How to validate text in Text widge
by ww (Archbishop) on Jan 03, 2016 at 13:30 UTC

    We're here to help you learn... but your question is tantamount to a "gimmé." Rather than ask others to solve your problem without any evidence of effort on your part (the gimmé), please read the documentation, write some code, and if that fails, debug. Then you'll be well served by asking Monks where the problem lies.


    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.
Re^3: How to validate text in Text widge
by Anonymous Monk on Jan 03, 2016 at 20:49 UTC
    #!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = tkinit; my $tt = $mw->Scrolled('anonText', -bg => 'white' ); $tt->pack( qw/-expand 1 -fill both / ); $mw->geometry('50x100'); $mw->WidgetDump; use Tk::WidgetDump; $tt->focus; $mw->MainLoop; BEGIN { package Tk::anonText; use base qw/ Tk::Derived Tk::Text /; Construct Tk::Widget 'anonText'; sub Insert { warn "@_ "; my( $w, $string ) = @_; return unless (defined $string && $string ne ''); return if $string eq ';'; return $w->SUPER::Insert( $string ); } 1; } __END__