Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Entry widget with explicit submit button

by 7stud (Deacon)
on Feb 16, 2013 at 18:17 UTC ( #1019053=note: print w/replies, xml ) Need Help??

in reply to Entry widget with explicit submit button

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019053]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2018-06-24 10:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.