Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Entry widget with explicit submit button

by amiksingh (Initiate)
on Feb 15, 2013 at 16:14 UTC ( #1018903=perlquestion: print w/ replies, xml ) Need Help??
amiksingh has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I need to make an entry widget with an explicit submit button, which should check data given by user and if correct only then changes the -textvariable associated with the entry widget.

Thanks!

Comment on Entry widget with explicit submit button
Re: Entry widget with explicit submit button
by choroba (Abbot) on Feb 15, 2013 at 16:54 UTC
    What GUI are you using? If it is Tk, read Validation in Tk::Entry.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Yes, I am using TK. I read Validation in Entry, but that gives you option of "focus" on entry box and "key". But what I need is a separate button for a user to validate it.

      (For example, a user may play around with the text in Entry box, but he may not choose to conform to changes and might close the window. So, I want a submit button alongwith it. Only when it is pressed, I'll take the input.)
        Such a functionality does not exist. You have to create a normal Tk::Button and implement the logic yourself in its -command.
        لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Entry widget with explicit submit button
by 7stud (Deacon) on Feb 16, 2013 at 18:17 UTC

    a user may play around with the text in Entry box, but he may not choose to conform to changes and might close the window. So, I want a submit button alongwith it. Only when it is pressed, I'll take the input.

    You can also intercept the 'window close' event and change a textvariable to anything you want:

    use strict; use warnings; use 5.012; use Tk; my $entry_text = 'Enter answer here'; #textvariable #======Main window========== my $mw = MainWindow->new; $mw->protocol("WM_DELETE_WINDOW", \&my_quit); sub my_quit { say "Window closing...$entry_text"; $entry_text = ''; say "-->$entry_text<---"; exit; } #======Entry================ my $entry = $mw->Entry( -textvariable => \$entry_text, )->pack; $entry->focus; $entry->selectionRange(0, 'end'); sub my_validator { if ($entry_text eq 'hello') { $entry_text = 'Try again!'; $entry->selectionRange(0, 'end'); $entry->icursor(0); } else { say "Thanks for the great input!"; say $entry_text; } } #========Button================= $mw->Button( -text => 'Submit', -command => \&my_validator, )->pack; MainLoop;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1018903]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2014-09-03 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls